jargon

bi 0.03 freebasic.bas

Jul 3rd, 2013
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'bi 0.03
  2. 'Binary Data Module
  3. 'Blitz Basic Source Code
  4. 'Copyright Wednesday, November 14th 2007 - July 3rd 2013 Timothy Robert Keal
  5. 'requires (none)
  6.  
  7. 'string to pointer
  8. Function bi_sp(value as string) as ptr
  9.     value=ucase(value)
  10.     dim as ptr ptr1=CreateBank(Len(value))
  11.     dim as long offset=0
  12.     do while offset<BankSize(ptr1)
  13.         PokeByte ptr1,offset,bi_a(Asc(Mid(value,offset+1,1)))
  14.         offset=offset+1
  15.     loop
  16.     Return ptr1
  17. End Function
  18.  
  19. 'transcode ascii char
  20. Function bi_a(ascii as long) as long
  21.     If ascii>=48 And ascii<=57 Then
  22.         Return ascii-48
  23.     ElseIf ascii>=65 And ascii<=90 Then
  24.         Return ascii-55
  25.     ElseIf ascii>=97 And ascii<=122 Then
  26.         Return ascii-87
  27.     ElseIf ascii=46 Then
  28.         Return 36
  29.     Else
  30.         Return 37
  31.     EndIf
  32. End Function
  33.  
  34. 'int to float
  35. Function bi_if(value as long) as double
  36.     dim as ptr temp=CreateBank(&H4)
  37.     PokeInt temp,0,value
  38.     dim as double ret=PeekFloat(temp,0)
  39.     FreeBank temp
  40.     Return ret
  41. End Function
  42.  
  43. 'float to int
  44. Function bi_fi(value as double) as ptr
  45.     dim as ptr temp=CreateBank(&H4)
  46.     PokeFloat temp,0,value
  47.     dim as ptr ret=PeekInt(temp,0)
  48.     FreeBank temp
  49.     Return ret
  50. End Function
Add Comment
Please, Sign In to add comment