+ Reply to Thread
Results 1 to 9 of 9

How to combine 4 Decimal numbers into a Hex number

Hybrid View

  1. #1
    Registered User
    Join Date
    12-09-2019
    Location
    pakistan
    MS-Off Ver
    2010
    Posts
    7

    How to combine 4 Decimal numbers into a Hex number

    Hi

    How to combine 4 Decimal numbers into a Hex number.

    If I have 4 decimal numbers each number is max 1 or 2 decimal digits and I have these in A, B, C and D Columns then how can I use some formula to combine these into a Hex number?

    The size of hex number will be 4-hex digits, that is 16-bits long. These 16-bits are divided in 4 groups of bits as follows:

    16-bits => (5-bits)--(1-bit)--(5-bits)--(5-bits)
    16-bits => 10101 --- 1 ------ 00001--- 00011
    Decimal => 21 ----- 1 ----------1 ------- 3
    Hex number => AC23

    So if I write 21, 1, 1, 3 in Col A, B, C, D then how can I get 'AC23' in Col E as shown in following image?

    21.jpg

    This post is reverse of my previous post on this forum in which I wanted to break a given Hex number into 4 decimal numbers.
    Its Title was "Converting HEX value to BIT-fields", and ID=1304645.

  2. #2
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: How to combine 4 Decimal numbers into a Hex number

    Formula for E1:

    =DEC2HEX(A1*2048+B1*1024+C1*32+D1)
    Safer version (to ensure no overflow) is:

    =DEC2HEX(BITAND(A1,31)*2048+BITAND(B1,1)*1024+BITAND(C1,31)*32+BITAND(D1,31))
    WBD
    Office 365 on Windows 11, looking for rep!

  3. #3
    Registered User
    Join Date
    12-09-2019
    Location
    pakistan
    MS-Off Ver
    2010
    Posts
    7

    Re: How to combine 4 Decimal numbers into a Hex number

    What will be Cell-Format to make this formula work? Should it be 'General', or 'Number', or 'Text' or something else?
    Will I get the result displayed in HEX format?

  4. #4
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: How to combine 4 Decimal numbers into a Hex number

    General or Text would be fine. Result is displayed exactly as in your screenshot. I'm guessing you didn't try it?

    WBD

  5. #5
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: How to combine 4 Decimal numbers into a Hex number

    Bit twiddling ...

    =DEC2HEX(BITLSHIFT(A1,11)+BITLSHIFT(B1,10)+BITLSHIFT(C1,5)+D1)
    =DEC2HEX(BITLSHIFT(BITAND(A1,31),11)+BITLSHIFT(BITAND(B1,1),10)+BITLSHIFT(BITAND(C1,31),5)+BITAND(D1,31))
    WBD

  6. #6
    Registered User
    Join Date
    12-09-2019
    Location
    pakistan
    MS-Off Ver
    2010
    Posts
    7

    Re: How to combine 4 Decimal numbers into a Hex number

    Your very first formula gives right results.
    The later 3 formulas are not working. I get this result for them:

    Attachment 661312

  7. #7
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2506
    Posts
    13,792

    Re: How to combine 4 Decimal numbers into a Hex number

    @ WBD

    BITAND (and all bit wise functions) are not available until Excel version 2013.
    Dave

  8. #8
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: How to combine 4 Decimal numbers into a Hex number

    Quote Originally Posted by FlameRetired View Post
    @ WBD

    BITAND (and all bit wise functions) are not available until Excel version 2013.
    Ah. I didn't realise this. Such a shame. I guess we'll have to take my first answer then

    WBD

  9. #9
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2506
    Posts
    13,792

    Re: How to combine 4 Decimal numbers into a Hex number

    Yes I agree. It is a shame.

+ 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] A Formula Which Turns Numbers Into Text With A Specific Decimal Number Amount
    By zanshin777 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-01-2018, 04:55 PM
  2. Replies: 3
    Last Post: 05-18-2016, 09:38 AM
  3. [SOLVED] Number Format to whole numbers, or if fraction, allow one decimal
    By chulho in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-12-2013, 05:42 PM
  4. Replies: 3
    Last Post: 08-28-2013, 08:45 AM
  5. [SOLVED] copy number with 3 or more decimal places and paste the actual value as 2 decimal number
    By k1dr0ck in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-29-2013, 12:57 AM
  6. Replies: 2
    Last Post: 05-08-2012, 02:44 AM
  7. My numbers format as a number with two decimal places.
    By Tim Poulter in forum Excel General
    Replies: 2
    Last Post: 09-17-2005, 09:05 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