Results 1 to 5 of 5

Thread: Hex to Binary using a divide and conquer approach for the first and second digit

  1. #1

    Hex to Binary using a divide and conquer approach for the first and second digit



    Register for a FREE account, and/
    or Log in to avoid these ads!

    I am trying to find a formula that convert Hex to Binary. I have already found one but now I am required to use a divide and conquer approach for the first and second digit.
    example:
    Input Hex B7 B= 1st digit 7= 2nd digit
    Binary 10110111
    someone suggest me to consider Right and Left functions to extract the digits from the input and “&” for concatenating strings… any formula suggestions?

    Thanks

  2. #2
    Conjurer CheshireCat's Avatar
    Join Date
    Dec 2011
    Location
    Victoria, Canada
    Posts
    121
    Articles
    0
    Excel Version
    Microsoft Excel 2013
    Seems like overkill considering HEX2BIN does this on it's own,

    Code:
    =HEX2BIN(A2,8)
    but if you insist on using LEFT and RIGHT and "&", and a maximum of two characters, try:

    Code:
    =CHOOSE(LEN(A2),HEX2BIN(A2,4),HEX2BIN(LEFT(A2,1),4)&HEX2BIN(RIGHT(A2,1),4))
    Cheers,
    Last edited by CheshireCat; 2012-07-17 at 06:38 AM.

  3. #3
    thank you so much... that's the formula i was trying to get... it works..

  4. #4
    Can you please help me to reverse this formula to Bin2hex?

  5. #5
    Conjurer CheshireCat's Avatar
    Join Date
    Dec 2011
    Location
    Victoria, Canada
    Posts
    121
    Articles
    0
    Excel Version
    Microsoft Excel 2013
    Again, you can do this with BIN2HEX like this:

    Code:
    =BIN2HEX(A2)
    or using LEFT & RIGHT like this:

    Code:
    =IF(LEN(A2)=8,IF(BIN2HEX(LEFT(A2,4),1)="0",BIN2HEX(RIGHT(A2,4),1),BIN2HEX(LEFT(A2,4),1)&BIN2HEX(RIGHT(A2,4),1)),"Requires 8 binary digits")
    Cheers,

Posting Permissions

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