Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Binary to Hex Conversion
Message
From
13/06/1997 21:24:22
 
 
To
13/06/1997 11:49:05
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00036266
Message ID:
00036342
Views:
35
> 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) With the discussion about Dec2Hex then Dec2Bin a short while ago, I was thinking about this very thing earlier today. Try this: * Initialize the input and output strings * We don't care how long they are m.lcInString = "1100001111010001" m.lcOutString = "" ? m.lcInString do while not empty(m.lcInString) * Break off the right 4 bits, PADL() if necessary if len(m.lcInString) > 4 m.lcParse = right(m.lcInString,4) m.lcInString = left(m.lcInString,len(m.lcInString)-4) else m.lcParse = padl(m.lcInString,4,"0") m.lcInString = "" endif * Do the 'Power of 2' thing for the four numbers m.lpTemp = 0 for m.lpCount = 0 to 3 m.lpTemp = m.lpTemp + (val(substr(m.lcParse,4-m.lpCount,1)) * 2^m.lpCount ) endfor * Accumulate the result m.lcOutString = substr("0123456789ABCDEF",m.lpTemp+1,1) + m.lcOutString enddo ? m.lcOutString
Paul Russell
EMail: prussell@fox.nstn.ca
Phone: (902) 499-5043
Previous
Reply
Map
View

Click here to load this message in the networking platform