Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Binary to Hex Conversion
Message
From
13/06/1997 19:02:23
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00036266
Message ID:
00036322
Views:
38
actually when converting binaru to hex it is much simpler to deal with sets of 4 bits becasue it is a 1-1 relation (s) create a short array (0-15) with the binary representation of the hex
0000  0
0001  1
.
1111   F
then you just take each 4 bits and take the appropriate number Arnon > > >I need to convert a binary number to Hex, and vice-versa. It's been a long > time since I've done this. Does anyone have some code that will do this for > me? > > > >The binary number will look something like: 1100001111010001 (It will be > as much as 16 digits) > > > >Craig > > Hi Craig, > > I'd suggest a two step approach, the first being to convert the binary > string to an integer, then covert the integer to hex. I recently saw a > routine to do the latter conversion, so here's the first part: > > FUNCTION BStr2Int > > LPARAMETER pc_bstr > > LOCAL lnresult, lni, lnj, lnlast > lnlast = LEN(pc_bstr) > lnj = -1 > lnresult = 0 > FOR lni = lnlast TO 1 STEP -1 > lnj = lnj + 1 > lnresult = lnresult + (VAL(SUBSTR(pc_bstr, lni, 1)) * (2 ^ lnj)) > NEXT > RETURN lnresult > > Regards, > > George >
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform