Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HEX64$ OCT64$ BIN64$
#1
To complement the new Longint type, here's a little lib including HEX64$,OCT64$ amd BIN64$ functions...
Code:
'BASE64 library by Antoni Gual  4/2005
'
Declare function bin64$(num as longint)
Declare function hex64$(num as longint)
Declare function oct64$(num as longint)


function bin64$(num as longint)
a$=string$(64,48) 'zero padded
b$=BIN$(cint (num shr 32)and &hFFFFFFFF)
mid$(a$,33-len(b$))=b$
b$=BIN$(cint (num and &hFFFFFFFF))
mid$(a$,65-len(b$))=b$
FUNCTION=a$
end function

function hex64$(num as longint)
a$=string$(16,48) 'zero padded
b$=hex$(cint(num shr 32and &hFFFFFFFF))
mid$(a$,9-len(b$))=b$
b$=hex$(cint (num and &hFFFFFFFF))
mid$(a$,17-len(b$))=b$
FUNCTION=a$
end function

function oct64$(num as longint)
a$=string$(22,48)  'zero padded
b$=oct$(cint(num shr 60)and &hf)
mid$(a$,3-len(b$))=b$
b$=oct$(cint ((num and &hFFFFFFFC0000000)shr 30))
mid$(a$,13-len(b$))=b$
b$=oct$(cint (num and &h3FFFFFFF))
mid$(a$,23-len(b$))=b$
FUNCTION=a$
end function
Antoni
Reply
#2
Thanks for these useful functions!

Another suggestion: it would be nice to have the following declared somewhere:

Code:
#define LONGINT_MAX    9223372036854775807   '  2^63 - 1
#define LONGINT_MIN   -9223372036854775808   ' -2^63
#define ULONGINT_MAX  18446744073709551615   '  2^64 - 1

I did not find them in CRT.BI
ean Debord
----------------
Math library for FreeBasic:
http://www.unilim.fr/pages_perso/jean.de...fbmath.zip
Reply
#3
CRT.bi is perhaps not the right place, but they should be somewhere..
Antoni
Reply
#4
Antoni, mind if I put that code up on plantasy for download?
Reply
#5
You are welcome!
Antoni
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)