Convert large 18 digit integer numbers to Hexadecimal number

manikandan23

New Member
Joined
Sep 6, 2017
Messages
3
Hi, I am looking to convert large 18 digit (Product Serial Numbers - Electronic Serial Numbers) numbers to its equivalent Hexadecimal numbers.

Since my number is huge, I am getting #NUM ! error when I use DEC2HEX function.

Can anyone please suggest me how do I do that in Excel?

My data looks like below: (Only some sample ESNs I posted here. But my excel is a huge list of ESNs to be converted to its equivalent Hex value)
[TABLE="width: 139"]
<colgroup><col></colgroup><tbody>[TR]
[TD]256691622700551235[/TD]
[/TR]
[TR]
[TD]256691622700554551[/TD]
[/TR]
[TR]
[TD]256691622700554513[/TD]
[/TR]
[TR]
[TD]256691622700553880[/TD]
[/TR]
[TR]
[TD]256691622700553570[/TD]
[/TR]
[TR]
[TD]256691622700553001[/TD]
[/TR]
[TR]
[TD]256691622700169272[/TD]
[/TR]
[TR]
[TD]256691622700554824[/TD]
[/TR]
[TR]
[TD]256691622700555366[/TD]
[/TR]
[TR]
[TD]256691622700553315[/TD]
[/TR]
[TR]
[TD]256691622700554353[/TD]
[/TR]
[TR]
[TD]256691622700627288[/TD]
[/TR]
[TR]
[TD]256691622700550435[/TD]
[/TR]
[TR]
[TD]256691622700554581[/TD]
[/TR]
[TR]
[TD]256691622700554614[/TD]
[/TR]
[TR]
[TD]256691622700615734[/TD]
[/TR]
[TR]
[TD]256691622700410773[/TD]
[/TR]
[TR]
[TD]256691622700590150[/TD]
[/TR]
[TR]
[TD]256691622700590217[/TD]
[/TR]
[TR]
[TD]256691622700590725[/TD]
[/TR]
[TR]
[TD]256691622700590695[/TD]
[/TR]
</tbody>[/TABLE]

Thanks in Advance!
Mani A
 
I was wondering how the code could be changed to give the hexdec in reverse order.
For example the hex return for 1,000 = 3E8 but the reverse needed to poke would be E8 03
Give this function a try...
Code:
Function DecToHexRev(ByVal V As Variant, Optional WithSpaces As Boolean = True) As String
  Do Until V = 0
    DecToHexRev = DecToHexRev & Mid("0123456789ABCDEF", CDec(V) - 16 * Int(CDec(V) / 16) + 1, 1)
    V = Int(CDec(V) / 16)
  Loop
  If Len(DecToHexRev) Mod 2 Then DecToHexRev = "0" & DecToHexRev
  If WithSpaces Then DecToHexRev = Trim(Format(DecToHexRev, Application.Rept("@@ ", Len(DecToHexRev))))
End Function
Note: I added an optional argument which controls whether spaces will be used to separate the output into space delimited hex-pairs or not. I defaulted it to True because your example showed you wanted the spaces. To suppress the spaces, simply pass False in for the optional argument.
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Give this function a try...
Code:
Function DecToHexRev(ByVal V As Variant, Optional WithSpaces As Boolean = True) As String
  Do Until V = 0
    DecToHexRev = DecToHexRev & Mid("0123456789ABCDEF", CDec(V) - 16 * Int(CDec(V) / 16) + 1, 1)
    V = Int(CDec(V) / 16)
  Loop
  If Len(DecToHexRev) Mod 2 Then DecToHexRev = "0" & DecToHexRev
  If WithSpaces Then DecToHexRev = Trim(Format(DecToHexRev, Application.Rept("@@ ", Len(DecToHexRev))))
End Function
Note: I added an optional argument which controls whether spaces will be used to separate the output into space delimited hex-pairs or not. I defaulted it to True because your example showed you wanted the spaces. To suppress the spaces, simply pass False in for the optional argument.


Though this code does reverse the output it only mirrors it instead of giving reverse byte output.
What I am needing it to do is return the (3E8) hexdec value as E8 03, your code gives the return as 08 E3.
 
Upvote 0
Taking a decimal value of 1000 = 03 E8 in Hex
what I need is for it to read the byte in reverse, starting with the first byte as E8 and the second as 03 and output it as E8 03
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top