|
-
August 5th, 1999, 08:13 AM
#1
Convert hexadecimal number to binary and reverse
How can I convert a hexadecimal number to binary and the reverse? I went to:
www.planet-source-code.com/vb
but code is missing there :-(
Urgent plz!!!
Michael Vlastos
Company MODUS SA
Development Department
Athens, Greece
Tel: +3-01-9414900
-
August 5th, 1999, 08:27 AM
#2
Re: Convert hexadecimal number to binary and reverse
-
August 5th, 1999, 08:56 AM
#3
Re: Convert hexadecimal number to binary and reverse
Nice try but didn't work:
The result (binary->hex) LOSES data. I mean that i lose some digits when the number is double!!!
I don't think is a bug of the code. The fault is at the data types (long, double etc.). Anyway, it didn't worked for my numbers :-( but thank you!
Michael Vlastos
Company MODUS SA
Development Department
Athens, Greece
Tel: +3-01-9414900
-
August 5th, 1999, 10:13 AM
#4
Re: Convert hexadecimal number to binary and reverse
I wrote a conversion from a Byte array once to see the bits of a monochrome bitmap in binary. I trashed the code but it went something like this:
Take the length in bits of the data type youre converting and set up a loop.
Inside the loop compare each bit of the number using the IIf function.
string1=IIf((number/2^n) & 1, "1", "0")
n=n+1
string2=string2 & string1
where n starts at 0 and loops up to total bits - 1
(or something like that)
Anyway it seems to me you could reverse the process and parse the string back into bits and dump them into a variant. Then just Hex the variant. I know Double and Single are stored internally in exponential format which may be causing your problem but wouldn't the variant automatically promote data types for you thereby solving the problem?
Just an idea...
-
August 6th, 1999, 05:09 AM
#5
Re: Convert hexadecimal number to binary and reverse
Your solution worked but I think the reverse doesn't. Thanx anyway. I cannot not to rate it...
Michael Vlastos
Company MODUS SA
Development Department
Athens, Greece
Tel: +3-01-9414900
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|