It's terrible when your memory goes
I can't remember what the first is...
------------------
Bin32$(-1???) = 00000000000000001111111111111111 = 65,535 instead of 11111111111111111111111111111111 = -1
FUNCTION Long2Bin(BYVAL rlngNumber AS LONG) AS STRING DIM i AS LOCAL INTEGER DIM ptrDigit AS LOCAL BYTE PTR DIM strResult AS STATIC STRING * 32 LSET strResult = "00000000000000000000000000000000" ptrDigit = VARPTR32(strResult) + 31 FOR i = 1 TO 32 IF rlngNumber& MOD 2 THEN @ptrDigit = &H31 END IF SHIFT RIGHT rlngNumber&, 1 DECR ptrDigit NEXT FUNCTION = strResult END FUNCTION
FUNCTION Long2Bin(BYVAL rlngNumber AS LONG) AS STRING DIM ptrDigit AS LOCAL BYTE PTR DIM strResult AS STATIC STRING * 32 LSET strResult = "00000000000000000000000000000000" ptrDigit = VARPTR32(strResult) + 32 WHILE rlngNumber& DECR ptrDigit IF rlngNumber& MOD 2 THEN @ptrDigit = &H31 END IF SHIFT RIGHT rlngNumber&, 1 WEND FUNCTION = strResult END FUNCTION
printmystuff(0) printmystuff(1) printmystuff(-1) printmystuff(65535) printmystuff(65536) printmystuff(-65535) printmystuff(-65536) printmystuff(2147483647) printmystuff(-2147483648) FUNCTION printmystuff(a&) print "Number =" + str$(a&) print bin$(a&) print binfmt$(a&,32) ' From help screen. print bin32$(a&) ' From Dave Stanton END FUNCTION FUNCTION BinFmt$(value&,size%) ' returns a binary string of size% digits if value& < 0 then BinFmt$ = RIGHT$("111111111111111"+BIN$(value&),size%) else BinFmt$ = RIGHT$("000000000000000"+BIN$(value&),size%) end if END FUNCTION FUNCTION Bin32$(N&) FUNCTION = BIN$(N& \ 65536)+ BIN$(n& MOD 65536) END FUNCTION Number = 0 0 0000000000000000 00 Number = 1 1 0000000000000001 01 Number =-1 1111111111111111 1111111111111111111111111111111 01111111111111111 Number = 65535 1111111111111111 0000000000000001111111111111111 01111111111111111 Number = 65536 10000000000000000 00000000000000010000000000000000 10 Number =-65535 11111111111111110000000000000001 11111111111111110000000000000001 011111111111111110000000000000001 Number =-65536 11111111111111110000000000000000 11111111111111110000000000000000 11111111111111110 Number = 2147483647 1111111111111111111111111111111 01111111111111111111111111111111 1111111111111111111111111111111 Number =-2147483648 10000000000000000000000000000000 10000000000000000000000000000000 10000000000000000
te$ = bin$(x) do until len(te$) = 32 te$ = "0" + te$ loop
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: