+ Reply to Thread
Results 1 to 21 of 21

Hexadecimal to text/decimal

  1. #1
    Registered User
    Join Date
    05-11-2021
    Location
    New York, USA
    MS-Off Ver
    Microsoft Office 2019
    Posts
    14

    Hexadecimal to text/decimal

    Hello,

    I have strings of hex code that I want excel to automatically convert to text or decimal. Here's a photo of my sheet:

    Untitled.png

    I want the formula to calculate the data from the colored fields and out put to text in the output field below it. How would I go about doing that?

  2. #2
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,742

    Re: Hexadecimal to text/decimal

    Hex to decimal is clear. But what do you mean by HEX to text?
    and could you attached sample file (check yellow banner at the top of the page).
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  3. #3
    Registered User
    Join Date
    05-11-2021
    Location
    New York, USA
    MS-Off Ver
    Microsoft Office 2019
    Posts
    14

    Re: Hexadecimal to text/decimal

    Thanks a lot for the help. This is actually hex data from an old video game. I'm trying to have excel convert the raw hex to more readable text/number data (if that makes sense). The hex data under the NAME DATA field in my attached document translates to text.
    Attached Files Attached Files

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Hexadecimal to text/decimal

    For name, it looks like it should be as simple as =CHAR(HEX2DEC(B5)) copied across.

    As near as I can tell, many of the other fields will just be HEX2DEC() function to convert from hexadecimal number to a decimal number.

    Some fields appear to need to split the hexadecimal string into 2 bytes (LEFT(hex#,1) and RIGHT(hex#,1)), then use that result in a lookup function based on the table below INDEX(leftcolumn,MATCH(partialhex#,rightcolumn,0))

    A couple of fields have you convert a number from HEX2DEC, then apply a HEX2DEC() multiplier. For example S5 =HEX2DEC(S4) and T5 =S5+256*HEX2DEC(T4)

    I'm not sure how much detail you need help with, but it appears to basically come down to using the HEX2DEC() function to get the decimal value from row 4, then use that value to get the desired result.
    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
    05-11-2021
    Location
    New York, USA
    MS-Off Ver
    Microsoft Office 2019
    Posts
    14

    Re: Hexadecimal to text/decimal

    Quote Originally Posted by MrShorty View Post
    I'm not sure how much detail you need help with.
    As much as I can get hopefully haha.

    I've worked with formulas before, but how do I get them to calculate data in one or multiple cells and then output to another? For example, I want all the hex data from the NAME DATA INPUT field to be translated to text into the NAME DATA OUTPUT field. Once I figure that out, I should be able to use your explanations above to do the same with the other cells. Thanks a lot!

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Hexadecimal to text/decimal

    I'm not sure I understand your question about the names. I put =CHAR(HEX2DEC(B4)) into B5. Copied/pasted/filled this formula into C5:P5, which gives the name KEN GRIFFEY JR in the output field (each character in its own cell). If you decide you need to join the characters together into a single text string, then you can use TEXTJOIN() or CONCAT() functions (assuming they are available to you. MSFT sometimes hides these newer functions behind subscription walls).

  7. #7
    Registered User
    Join Date
    05-11-2021
    Location
    New York, USA
    MS-Off Ver
    Microsoft Office 2019
    Posts
    14

    Re: Hexadecimal to text/decimal

    This has been unbelievably helpful. Thanks a lot.

    Quote Originally Posted by MrShorty View Post
    Some fields appear to need to split the hexadecimal string into 2 bytes (LEFT(hex#,1) and RIGHT(hex#,1)), then use that result in a lookup function based on the table below INDEX(leftcolumn,MATCH(partialhex#,rightcolumn,0))
    Yes you're absolutely right about needing to split the byte into two values. I'm honestly a little lost on how I would enter this formula into a cell (for example, in Q5) to reference the table below though...

    EDIT: I guess I'm not sure how I would combine the result of the left and right function to reference a lookup function.
    Last edited by eagle_3ye; 05-11-2021 at 12:52 PM.

  8. #8
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Hexadecimal to text/decimal

    It's not clear to me exactly what the output in Q5 would be. Based on what I understand:

    1) A LEFT() function to get the first digit of the hex number LEFT(Q4,1)
    1a) The output of the LEFT() and RIGHT() functions is a text string. For Excel, the text string "4" is different from the number 4, so you need to make sure that you are comparing the correct value. Either make sure that all of your numbers in S8:S10 are really text strings (preceded by an apostrophe when entering) or change the text from the LEFT() function to a real number. Using the latter strategy via the VALUE() function VALUE(LEFT(...))
    2) Then a MATCH() function to find which row matches that number. MATCH(VALUE(...),S8:S10,0) This will return the row # that matches the first digit or N/A if the first digit doesn't match anything.
    3) Then an INDEX() function to find return the corresponding bat -- hand text from Q8:Q10 =INDEX(Q8:Q10,MATCH(...))

    That will tell you which hand they bat with. The position played is similar =INDEX(Q13:Q21,MATCH(VALUE(RIGHT(Q4,1)),S13:S21,0))

    From there I'm not sure if you want to try to combine bat hand and position into a single text string in Q5 (Q5 =INDEX(bat hand stuff)&INDEX(position stuff), or if you want bat hand and position in separate cells or just what you want to do.

  9. #9
    Registered User
    Join Date
    05-11-2021
    Location
    New York, USA
    MS-Off Ver
    Microsoft Office 2019
    Posts
    14

    Re: Hexadecimal to text/decimal

    Awesome. That all makes sense. Using your formulas, I was able to work out several of the fields. I've since revised the document (attached) and am having some difficulty working a formula for S5. Basically, I want the value to be hex2dec of S4 plus the value of T4 referenced from the table at Y16. To start, I'm trying to do a formula to call the value of T4 . Here's what I've got:

    =INDEX(Y18:Y21,MATCH(VALUE(T4),AA18:AA21))

    I keep getting an NA error though.

  10. #10
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Hexadecimal to text/decimal

    Your revised file did not attach.

    You have not included the 3rd argument in the MATCH() function, so MATCH() takes the VALUE(T4) number (the number 2, if the same input data as your original file in post #3) and compares it to the value in AA18. If VALUE(T4) is smaller than AA18, it returns N/A.

    My guess is that the values in AA18:AA21 are actually text strings, and we come back to the point I made in step 1a of post #8. Any number will always be smaller than any text string (the number 2 will be smaller than text strings like "01" or "02"), and thus, you get N/A errors for this. Look very carefully at what is in T4 and what is in AA18:AA21 and make sure you are comparing the same "type" of thing -- text or number.

  11. #11
    Registered User
    Join Date
    05-11-2021
    Location
    New York, USA
    MS-Off Ver
    Microsoft Office 2019
    Posts
    14

    Re: Hexadecimal to text/decimal

    Ah man. Okay it's attached to this message.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    05-11-2021
    Location
    New York, USA
    MS-Off Ver
    Microsoft Office 2019
    Posts
    14

    Re: Hexadecimal to text/decimal

    Once I'm able to call T4, it should just be a simple matter of adding an addition formula to add that to the decimal value of S4, right? Thanks again!!

  13. #13
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Hexadecimal to text/decimal

    As I suspected, when I open your file, the first thing I notice are green triangles on the AA18:AA21 and Y18:Y21 values. The error is "number stored as text". As explained, the number 2 (from VALUE(T4)) is smaller than the text string "0", so the MATCH() returns N/A.

    Two possible solutions -- which depends entirely on why you stored the "numbers" in AA18:AA21 as text strings and not numbers.

    Perhaps you are considering these as hexadecimal numbers (so they want to be stored as text) because in some variations these might be real hex numbers. If this is the case, then you need drop the VALUE() part inside of the MATCH() function and add a HEX2DEC() on the outside HEX2DEC(INDEX(Y18:Y21,MATCH(T4,AA18:AA21)))

    Or you need to store the numbers in AA18:AA21 (and Y18:Y21) as real decimal numbers not text strings, then use the formula as is.

    Where you want to add it to the hex number in S4 (after converting to decimal), I would probably prefer the latter approach, so that you don't end up with difficulties at the final addition step, but it is entirely up to you. The key is to keep careful track of when you are working with hexadecimal text strings and when you are working with decimal numbers and make sure you don't "cross compare" the two.

  14. #14
    Registered User
    Join Date
    05-11-2021
    Location
    New York, USA
    MS-Off Ver
    Microsoft Office 2019
    Posts
    14

    Re: Hexadecimal to text/decimal

    Okay... I thought I had converted them to decimal numbers from the drop down menu from the top, but now I see you can do it from the green arrow on each value. There's no functional reason why the numbers in the Y16 can't be decimal values. I'm having what might be a remedial issue... I don't know how to store them as decimals and prevent the leading 0 from disappearing. I've tried changing them to a custom 00 format, but that doesn't seem to be working.

  15. #15
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Hexadecimal to text/decimal

    I can think of no good reason for Excel to have trouble with a decimal number formatted as "00" so it displays the leading 0. Number formatting on Y18:Y21 and AA18:AA21 also should have no impact on whether the lookup function in S5 works or not. Is S4 working correctly now, or is there still some debugging to do? I notice that you are searching for the number 2 in AA18:AA21 which contain 0, 256, 512, 768. I wonder if you intend to search Y18:Y21 for the number 2, then return the value from AA18:AA21.

  16. #16
    Registered User
    Join Date
    05-11-2021
    Location
    New York, USA
    MS-Off Ver
    Microsoft Office 2019
    Posts
    14

    Unhappy Re: Hexadecimal to text/decimal

    Yep that's exactly what I want to do actually.

    I am... a flipping moron. Thanks a lot for pointing that out.
    Last edited by eagle_3ye; 05-12-2021 at 05:09 PM.

  17. #17
    Registered User
    Join Date
    05-11-2021
    Location
    New York, USA
    MS-Off Ver
    Microsoft Office 2019
    Posts
    14

    Re: Hexadecimal to text/decimal

    Okay I've attached another revised version of the sheet to this message. Now I'm trying to have excel look up the hex from Q25 and match it to what is displayed in the table at J29. I'm able to successfully pull data from the first two columns of the table, but how do I modify the formula to pull data from the entire table? I basically want it to match the hex data from Q25 with the hex lists in K30, M30, O30 and Q30 and the pull the corresponding B/T values in J30, L30, N30 and P30. I'm thinking I need to redo the table somehow...
    Attached Files Attached Files
    Last edited by eagle_3ye; 05-13-2021 at 10:49 AM.

  18. #18
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Hexadecimal to text/decimal

    If I understand, I would have expected the lookup table to be a long, 2 column table rather than 8 columns wide. Move L31:M61 down to J62. Repeat for columns N to Q. Then your lookup function need only search column K until it finds the correct value, then return the value from column J.

    Does that seem correct, or did I misunderstand something?

  19. #19
    Registered User
    Join Date
    05-11-2021
    Location
    New York, USA
    MS-Off Ver
    Microsoft Office 2019
    Posts
    14

    Re: Hexadecimal to text/decimal

    That’s exactly it! I thought I’d need to modify it to two columns. Gonna go give that a try.

  20. #20
    Registered User
    Join Date
    05-11-2021
    Location
    New York, USA
    MS-Off Ver
    Microsoft Office 2019
    Posts
    14

    Re: Hexadecimal to text/decimal

    Okay, the masterpiece is almost complete lol. I have another question. As you know, I'm working with a string of hex data. When I paste it into a row, it automatically assigns one hex nibble to a cell (and it unmerges merged cells). Is there a way to prevent it from doing this? In some instances, I want one nibble to occupy a merged cell that might take up two or more columns. Thanks!
    Last edited by eagle_3ye; 05-15-2021 at 08:59 AM.

  21. #21
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Hexadecimal to text/decimal

    Most experienced spreadsheet users avoid merged cells (probably for just these kinds of reasons), so I think most of the suggestions you will get from us will be the opposite of what you say you want. We will try to talk you out of using those merged cells.

    We will probably need you to explain exactly what is happening with this paste/import operation and what advantage you feel you are getting from the merged cell(s). Then we can talk about better options or help with merging those cells or something.

+ 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] Hexadecimal to decimal.
    By eemilv in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 09-17-2020, 10:19 AM
  2. Hexadecimal to Decimal
    By audi321 in forum Excel Formulas & Functions
    Replies: 32
    Last Post: 01-26-2017, 02:11 PM
  3. [SOLVED] VBA convert decimal to hexadecimal numbers
    By igormigor in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-17-2016, 08:23 AM
  4. Using a "Do Until" loop to convert decimal numbers to hexadecimal
    By georgiapeach in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-13-2014, 03:41 PM
  5. string to hexadecimal?
    By Mark121 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-01-2008, 10:26 AM
  6. [SOLVED] I want to convert a column of hexadecimal numbers to decimal num
    By xs2sandeep in forum Excel General
    Replies: 2
    Last Post: 04-04-2006, 04:50 AM
  7. CONVERT HEXADECIMAL CELL TO DECIMAL NUMBER
    By JAY in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-24-2005, 11:06 PM

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