|
Post by stan58 on Mar 8, 2019 3:33:55 GMT -5
Some time ago I was guided on how to convert a binary string into numeric as shown
B$="1010101" 'binary conversion
L=len(B$)
Number=0
for x=1 to L
bit$=mid$(B$,L-(x-1),1)
ans=val(bit$)
if ans=1 then
ans=2^(x-1)
Number=Number+ans
end if
next
print Number
end
Is there a way of doing the opposite i.e converting a string or number into a binary string
|
|
|
Post by tsh73 on Mar 8, 2019 3:48:55 GMT -5
Sure For example
function eightBitPattern$(num) for i = 0 to 7 eightBitPattern$ = str$((num and 2 ^ i) > 0) + eightBitPattern$ next i end function
(this one pads to 8 bit with 0's)
|
|
|
Post by stan58 on Mar 8, 2019 6:46:07 GMT -5
tsh 73 thank you
|
|