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

#### miki76

##### New member
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

#### CheshireCat

##### New member
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:

#### miki76

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

#### miki76

##### New member
Can you please help me to reverse this formula to Bin2hex?

#### CheshireCat

##### New member
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,