+ Reply to Thread
Results 1 to 19 of 19

DEC2HEX - HEX2DEC Issues - Number too Long?

  1. #1
    Registered User
    Join Date
    07-17-2014
    Location
    Farmington, mi
    MS-Off Ver
    2010
    Posts
    23

    DEC2HEX - HEX2DEC Issues - Number too Long?

    Hello Excel Forum,

    I have been having an issue with the excel DEC2HEX/HEX2DEC formula. I believe my issue is that my end number is too long. For example- I need to translate a big list of HEX numbers (i.e. A10000219A23D2) to DEC (i.e. 45317471814165458). When I use the formula "=HEX2DEC(A1)" - it doesn't do anything. It just shows the formula (see attached image).

    I have done the general googling and what I could find was that my end number is too large. Is it possible to input a 14 digit HEX number to produce the 17 digit DEC number?

    I am able to do the translation via the calculator using the programmer funtions. However, I have to translate over 1000 hex numbers....that will take forever using the calculator!

    Any help will be greatly appreciated!

    Thanks!

    hex to dec.PNG

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,033

    Re: DEC2HEX - HEX2DEC Issues - Number too Long?

    I have found here those UDF functions:

    Please Login or Register  to view this content.
    To avoid starting with A (as a negative number) you need to add 0 in the formula:

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Never use Merged Cells in Excel

  3. #3
    Registered User
    Join Date
    07-17-2014
    Location
    Farmington, mi
    MS-Off Ver
    2010
    Posts
    23

    Re: DEC2HEX - HEX2DEC Issues - Number too Long?

    Hello Zbor!

    I appreciate the very quick reply! It does look like that formula works, however, it spits out a DEC value that replaces the last two number values with zeroes. It is not the 'true' DEC number.

    zbor formula = 45317471814165400

    Actual DEC = 45317471814165458


    Do you know how to make it show the 'true' DEC number?


    Also, I got this all mixed up. I need to go the other way around. I need to change the DEC - 45317471814165458 to HEX - A10000219A23D2.

    Is that possible with the same formula?


    Thank you.
    Last edited by time4mzl; 04-12-2016 at 09:57 AM.

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,373

    Re: DEC2HEX - HEX2DEC Issues - Number too Long?

    Note that numbers that large go beyond standard double precision (~15 digits) that Excel uses to store numbers. If you need more than double precision can hold, you will need to figure out exactly how you want to do this -- which will probably depend a lot on what you are doing with these numbers.

    If you need to perform calculations on these numbers, you may consider peforming all calculations and storage in VBA using a Decimal data type that can store integers up to about 29 digits (see here for limits of different data types: https://msdn.microsoft.com/en-us/lib...=vs.60%29.aspx ).

    If there are not calculations needed, you may use VBA to convert from hexadecimal into a Decimal data type (not double or integer or long), then convert that Decimal data type to string and store the "numbers" in Excel as strings (though you may need to take extra measures to make sure Excel does not convert the "numbers as text" into numbers and truncate them to the limits of double precision).

    I'm sure there are other strategies as well. You are dealing with very large numbers here. Large enough that you will need to pay careful attention to data type and the limits imposed on those data types by whatever programming language you choose to use.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  5. #5
    Registered User
    Join Date
    07-17-2014
    Location
    Farmington, mi
    MS-Off Ver
    2010
    Posts
    23

    Re: DEC2HEX - HEX2DEC Issues - Number too Long?

    Hello mrShorty.

    This may be a repeated message - I sent a reply but I cannot see it.


    I apologize! I am a layman when it comes to excel- a lot of what you just said went way over my head. I am reviewing the link you posted and it seems like this is not possible without extensive knowledge on excel formulas.

    I do not need to do anything else but translate the DEC number (ex: 45317471814165458) to the HEX version (ex: A10000219A23D2). I have a list of 3000 DEC numbers.

    Am I better off just entering each into the calculator in PROGRAMMER mode and translating each individual number to HEX? Or is it possible to translate the whole list via excel?

    Thanks.

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,373

    Re: DEC2HEX - HEX2DEC Issues - Number too Long?

    As I indicated, some of the answer to these questions probably should be context dependent. Where are these DEC numbers coming from? How are they being used?

    Am I better off just entering each into the calculator in PROGRAMMER mode and translating each individual number to HEX? Or is it possible to translate the whole list via excel?
    the "best" approach might be to abandon Excel in favor of a programming language with good support for very large numbers. But, I get the impression that you are unfamiliar -- not only with Excel -- but other programming languages as well.

    If it must be done in Excel, we probably need to think through how to process a very large "number stored as text" (large enough that we can never allow it to be stored as a number) and convert to a hexidecimal string. I will think on it, and see what I can think up.

  7. #7
    Registered User
    Join Date
    07-17-2014
    Location
    Farmington, mi
    MS-Off Ver
    2010
    Posts
    23

    Re: DEC2HEX - HEX2DEC Issues - Number too Long?

    MrShorty,

    Where are these DEC numbers coming from? How are they being used?
    I have about 3000 devices that I scanned into excel - I scanned their DEC value off the box. However, in order for our partner to add these devices to the server - they need the values in HEX. There is no other use for this other than that. I just need the list of 3000 DEC values translated to HEX.

    For Example:

    hex to dec.PNG


    Also, I can easily translate DEC to HEX via the windows calculator - it seems odd to me that it is so easy with that program but really difficult in excel. Is there any way to replicate what the calculator is doing for a list?

    Thanks for the help!

  8. #8
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,373

    Re: DEC2HEX - HEX2DEC Issues - Number too Long?

    I can easily translate DEC to HEX via the windows calculator - it seems odd to me that it is so easy with that program but really difficult in excel. Is there any way to replicate what the calculator is doing for a list?
    As near as I can tell, MS has programmed the Windows Calculator with quad-precision (~30 digit) support. Excel, for all versions (I suppose I cannot verify the newest version) is limited to double precision. I cannot explain why MS has not added quad-precision support to Excel. Some day, when you get a chance to ask the Excel Gods, you can ask them why they did not see fit to provide support for higher precision than double precision in Excel.

    As I indicated -- this is easy in a program/programming language which supports very large, very precise numbers like this.

    As tedious as it might be, it might be faster to do these by hand in Windows calculator.

  9. #9
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,373

    Re: DEC2HEX - HEX2DEC Issues - Number too Long?

    After further research, zbor's DHex() function will work, if we adapt it to use Decimal instead of double data type. Note this page that describes the use of Decimal data type in VBA; https://msdn.microsoft.com/en-us/lib.../gg251687.aspx

    We need to input the number to the UDF as a string. Dim Nb and Nb2 as variants instead of doubles, and then the rest of the code should work normally.
    Please Login or Register  to view this content.

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: DEC2HEX - HEX2DEC Issues - Number too Long?

    Another way:

    A
    B
    C
    1
    45317471814165458 A10000219A23D2 B1:=sCur2Hex(A1)


    Please Login or Register  to view this content.
    Last edited by shg; 04-12-2016 at 01:17 PM. Reason: missed a function
    Entia non sunt multiplicanda sine necessitate

  11. #11
    Registered User
    Join Date
    07-17-2014
    Location
    Farmington, mi
    MS-Off Ver
    2010
    Posts
    23

    Re: DEC2HEX - HEX2DEC Issues - Number too Long?

    Hello shg,

    Yes, your formula seems to work. How do I go about using that in the spreadsheet? I copied the C1 formula but it does not seem to 'auto solve' (not sure what the term is).

    Do I need to do something with the code provided?

    I apologize for the lack of knowledge on excel. I am a nooby dan.

    Thanks.

  12. #12
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: DEC2HEX - HEX2DEC Issues - Number too Long?

    C1 is showing the formula that goes in B1. i.e.,

    =sCur2Hex(A1)

  13. #13
    Registered User
    Join Date
    07-17-2014
    Location
    Farmington, mi
    MS-Off Ver
    2010
    Posts
    23

    Re: DEC2HEX - HEX2DEC Issues - Number too Long?

    When I used that formula, the cell says: '#NAME?'. I think I am doing something wrong XD

    Is there another step I must take other than copying the formula into the cell and replacing the 'A1' with the corresponding cell?

    hex to dec.PNG

  14. #14
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: DEC2HEX - HEX2DEC Issues - Number too Long?

    You need to put the code in the workbook and save as an xlsm file:

    Adding a Macro or UDF to a Standard Module
    1. Copy the code from the post
    2. Press Alt+F11 to open the Visual Basic Editor (VBE)
    3. From the menu bar in the VBE window, do Insert > Module
    4. Paste the code in the window that opens
    5. Press Alt+Q to close the VBE and return to Excel

  15. #15
    Registered User
    Join Date
    07-17-2014
    Location
    Farmington, mi
    MS-Off Ver
    2010
    Posts
    23

    Re: DEC2HEX - HEX2DEC Issues - Number too Long?

    OMG IT WORKED!

    I sware you are going to get me a raise XD

    Thank you so much!!!!!

  16. #16
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: DEC2HEX - HEX2DEC Issues - Number too Long?

    You're welcome.

  17. #17
    Registered User
    Join Date
    05-21-2018
    Location
    Sydney, Australia
    MS-Off Ver
    2016
    Posts
    8

    Re: DEC2HEX - HEX2DEC Issues - Number too Long?

    Hi shg,

    I know the above post is a few years old now but I'm wondering if you could help me, I need to convert a 14 digit HEX number into DEC number for programming access control fobs.

    I see the above method worked for DEC to HEX but have no idea how to reverse it.

    Your help would be very much appreciated.

  18. #18
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,387

    Re: DEC2HEX - HEX2DEC Issues - Number too Long?

    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  19. #19
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: DEC2HEX - HEX2DEC Issues - Number too Long?

    Start a new thread -- we'll get you sorted.

    A
    B
    C
    1
    Hex
    Decimal String
    2
    FFFFFFFFFFFFFF
    72057594037927935
    B2: =HexToDecStr(A2)
    3
    FFFFFFFFFFFFFFFFFFFFFFFF
    79,228,162,514,264,337,593,543,950,335
    B3: =HexToDecStr(A3, ",")
    4
    123456789ABCDEF
    81 985 529 216 486 895
    B4: =HexToDecStr(A4, " ")
    5
    FFFFFFFFFFFFFFFFFFFFFFFF
    79228162514264337593543950335
    B5: =HexToDecStr(A5)
    Last edited by shg; 07-11-2019 at 07:35 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] DEC2HEX Failing within Macros
    By klotzy in forum Excel General
    Replies: 13
    Last Post: 09-28-2016, 10:17 AM
  2. Number format to Display 20 character long number.
    By SamCV in forum Excel General
    Replies: 6
    Last Post: 07-09-2014, 08:19 PM
  3. [SOLVED] =IF and =SUMIF formulas creating long long long data processing times.
    By comp in forum Excel Programming / VBA / Macros
    Replies: 32
    Last Post: 03-26-2014, 02:59 PM
  4. Hex2Dec and Dec2Hex don't work
    By Robin Clay in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-17-2013, 07:24 PM
  5. Long running vb/a code Issues
    By toddbailey in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 03-03-2012, 06:01 PM
  6. Long Number Col
    By JXBlack in forum Excel General
    Replies: 1
    Last Post: 01-26-2010, 09:28 PM
  7. Changin =DEC2HEX conversion
    By ConfusedTech in forum Excel General
    Replies: 7
    Last Post: 12-19-2007, 02:09 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1