Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Binary
Message
 
To
01/03/2006 03:52:02
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Re: Binary
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01100270
Message ID:
01100277
Views:
17
Hi Jos,

MartinJ
clear
?"binary, 32 bits"
li=739207
li=DNaBIN(li,2,32)
?li
li=BINnaD(li,2)
?li


?"hexa, 8 digits"
li=739207
li=DNaBIN(li,16,8)
?li
li=BINnaD(li,16)
?li

?"okta, 12 digits"
li=739207
li=DNaBIN(li,8,12)
?li
li=BINnaD(li,8)
?li

*********************************************************************
* 1996
* Convert decimal number to 2-16
*
*********************************************************************
PROCED DnaBIN
PARAM  dcislo,binsous,binformat
private hcislo,itcislo,zcislo,rcislo,dcislo,binsou,binformat
private znak

dime znak(16)
znak(1)='0'
znak(2)='1'
znak(3)='2'
znak(4)='3'
znak(5)='4'
znak(6)='5'
znak(7)='6'
znak(8)='7'
znak(9)='8'
znak(10)='9'
znak(11)='A'
znak(12)='B'
znak(13)='C'
znak(14)='D'
znak(15)='E'
znak(16)='F'


hcislo=''
itcislo=2
do while  itcislo>0
   itcislo=int(dcislo/binsous)
   zcislo=iif(itcislo<1,dcislo,dcislo%binsous)
   hcislo=znak(zcislo+1)+hcislo
   dcislo=itcislo
enddo
rcislo=binformat-len(hcislo)
rcislo=iif(rcislo<0,0,rcislo)
hcislo=repl('0',rcislo)+hcislo
return hcislo

*********************************************************************
*
* Convert from 2-16 to decimal
*
*********************************************************************
PROCED BINnaD
PARAM bincislo,dsous
private ddelka,icount,zkde,expo,ycount,expocis,dcislo,bincislo,dsous
private znak
dime znak(16)
znak(1)='0'
znak(2)='1'
znak(3)='2'
znak(4)='3'
znak(5)='4'
znak(6)='5'
znak(7)='6'
znak(8)='7'
znak(9)='8'
znak(10)='9'
znak(11)='A'
znak(12)='B'
znak(13)='C'
znak(14)='D'
znak(15)='E'
znak(16)='F'

bincislo=allt(bincislo)
ddelka=len(bincislo)
dcislo=0
for icount=ddelka to 1 step -1
    zkde=ascan(znak,subs(bincislo,icount,1))
    expo=ddelka-icount
    expocis=1
    for ycount=1 to expo
        expocis=dsous*expocis
    next
    dcislo=dcislo+expocis*(zkde-1)
next

return dcislo
>>>Hi All,
>>>
>>>Is there a quick function to convert a number to binary and back again? i.e.
>>>
>>>
>>>A number like
>>>739207
>>>convert to
>>>10110100011110000111
>>>convert back to
>>>739207
>>>
>>>
>>>I have manually programmed this with BITTEST() each bit in the number but was wondering if there is a simpler function / method that I'm not aware of.
>>>
>>>Thanks
>>
>>
>>Jos,
>>
>>There's nothing simpler I'm aware of
>>
>>If it's only for occasional use, the bittest() will do fine
>>
>>You could speed it up by handling half a byte or one byte at a time.
>>Then you would have an array with the value of the (half) byte + 1 as an index into the array and the value of the element would be '0000', '0001', etc
>
>Hi Gregory. I see. But how to easily convert the binary number back to the original number?
"Navision is evil that needs to be erazed... to the ground"

Jabber: gorila@dione.zcu.cz
Jabber? Jabbim
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform