![]() |
Converting hex to ascii
How do I convert a hex byte into an ascii character? I'll take an
excel formula or VB code. Either way would be fine. I could not find an excel function to do this. I appreciate any help submitted. Thank you. tom |
Converting hex to ascii
It's confusing to say "hex byte" because that's mixing presentation with
storage. A Byte is a Byte and can be presented as decimal, hexadecimal, binary, etc... So, by Hex Byte I assume you actually mean hex string. The first is Byte to Ascii, the secon is HexString to Ascii. Sub test() Dim byt As Byte, str As String byt = &H41 'A Debug.Print Chr(byt) str = "41" Debug.Print Chr("&H" & str) End Sub -- Rob van Gelder - http://www.vangelder.co.nz/excel "Tom" wrote in message om... How do I convert a hex byte into an ascii character? I'll take an excel formula or VB code. Either way would be fine. I could not find an excel function to do this. I appreciate any help submitted. Thank you. tom |
Converting hex to ascii
Hello,
To be able to work with hex numbers you have to install the Add-In "Analysis Toolpack" first (Tools Menu, Add-Ins and check the Analysis Toolpack checkbox). You may need the Office Installation CD to do this. When this is done you find a new function category (Insert Function) with the name "Engineering". In this function category you fine several functions like Hex2Dec. In VB it seems to be more complicated. The sub: Dim Dec1 As Long Dec1 = "&hF" End Sub will return the value 15 for Dec1, but if you use a variable input like in this sub: Dim Hex1 As String Dim Dec1 As Long Sub HexTest() Hex1 = "F" Dec1 = "&h(Hex1)" End Sub Then I get a "type mismatch" error. So if someone can help me how to avoid this problem I wil be very grateful. Thanks beforehand, Gerrit In EXCEL you have to install the "Tom" schreef in bericht om... How do I convert a hex byte into an ascii character? I'll take an excel formula or VB code. Either way would be fine. I could not find an excel function to do this. I appreciate any help submitted. Thank you. tom |
Converting hex to ascii
Two possibilities:
Sub HexTest() Dim hex1 As String Dim dec1 As Integer hex1 = "F" dec1 = "&h" & hex1 MsgBox dec1 hex1 = "ff" MsgBox hx2dc(hex1) End Sub Function hx2dc(s$) As Long hx2dc = "&h" & s$ End Function Gerrit van Stempvoort wrote: Hello, To be able to work with hex numbers you have to install the Add-In "Analysis Toolpack" first (Tools Menu, Add-Ins and check the Analysis Toolpack checkbox). You may need the Office Installation CD to do this. When this is done you find a new function category (Insert Function) with the name "Engineering". In this function category you fine several functions like Hex2Dec. In VB it seems to be more complicated. The sub: Dim Dec1 As Long Dec1 = "&hF" End Sub will return the value 15 for Dec1, but if you use a variable input like in this sub: Dim Hex1 As String Dim Dec1 As Long Sub HexTest() Hex1 = "F" Dec1 = "&h(Hex1)" End Sub Then I get a "type mismatch" error. So if someone can help me how to avoid this problem I wil be very grateful. Thanks beforehand, Gerrit In EXCEL you have to install the "Tom" schreef in bericht om... How do I convert a hex byte into an ascii character? I'll take an excel formula or VB code. Either way would be fine. I could not find an excel function to do this. I appreciate any help submitted. Thank you. tom |
Converting hex to ascii
Thanks for your help Rob. I guess I had an older version of VB help
because I could not find any leads to the chr() function. tom "Rob van Gelder" wrote in message ... It's confusing to say "hex byte" because that's mixing presentation with storage. A Byte is a Byte and can be presented as decimal, hexadecimal, binary, etc... So, by Hex Byte I assume you actually mean hex string. The first is Byte to Ascii, the secon is HexString to Ascii. Sub test() Dim byt As Byte, str As String byt = &H41 'A Debug.Print Chr(byt) str = "41" Debug.Print Chr("&H" & str) End Sub -- Rob van Gelder - http://www.vangelder.co.nz/excel "Tom" wrote in message om... How do I convert a hex byte into an ascii character? I'll take an excel formula or VB code. Either way would be fine. I could not find an excel function to do this. I appreciate any help submitted. Thank you. tom |
All times are GMT +1. The time now is 12:39 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com