I have a question about unit conversions. First, I have data which is recorded in hex and I'm tying to convert it to binary. If the hex number is numerical, excel treats it as an integer (1840). If it contains a letter (C08A) excel treats it as text. So I'm trying to create code that will find the first value (MSB); C in the example above. Then convert this value to binary and then move to the next hex value. After conversion, I need to reassemble these values from MSB to LSB.
Your assistance would be greatly appreciated.
Excel Conversion
Moderator: DPlotAdmin
- DPlotAdmin
- Posts: 2312
- Joined: Tue Jun 24, 2003 9:34 pm
- Location: Vicksburg, Mississippi
- Contact:
On the spreadsheet you can use HEX2DEC, as in
=HEX2DEC(A1) (if your hex value is in cell A1)
and
=INT(B1/256)+256*MOD(B1,256)
to byte-swap, assuming your converted decimal value is in B1.
A nice feature about HEX2DEC is it doesn't assume anything about your input: HEX2DEC(1840) will treat 1840 as a hexadecimal value even though it shows as a normal decimal number on your sheet.
In VBA you just need to add WorksheetFunction, as in:
Cells(1,2) = WorksheetFunction.Hex2Dec(Cells(1,1))
=HEX2DEC(A1) (if your hex value is in cell A1)
and
=INT(B1/256)+256*MOD(B1,256)
to byte-swap, assuming your converted decimal value is in B1.
A nice feature about HEX2DEC is it doesn't assume anything about your input: HEX2DEC(1840) will treat 1840 as a hexadecimal value even though it shows as a normal decimal number on your sheet.
In VBA you just need to add WorksheetFunction, as in:
Cells(1,2) = WorksheetFunction.Hex2Dec(Cells(1,1))
Visualize Your Data
support@dplot.com
support@dplot.com
-
- Posts: 21
- Joined: Thu Dec 10, 2009 10:55 pm