Decompose binary into decimal units, tens and hundreds

1k Views Asked by At

I have a 9 bit binary sequence (from 0 0000 0000 to 1 1111 1111) and I'd like to decompose into decimal units, tens and hundreds.

Consider the following:

0 0111 1011 ==> 123

I'd like to decompose it into:

0001 => 1  
0010 => 2  
0011 => 3  

Having 3 different functions (one for units one for tens and one for hundreds) is preferable

Would it be possible to get from any 9 bit sequence from 3 functions a decomposition?
One function would do units, one would do tens and another would handle hundreds.

It would be even better using logic only (AND, NAND, NOT, OR, XOR, NOR and NXOR)

Thanks for your time ;)

1

There are 1 best solutions below

3
On

It looks like you are doing natural binary coded decimal on the numbers $0$ to $511$. If your number is $N$, then $H=\lfloor N/100 \rfloor, T=\lfloor (N-100H)/10 \rfloor, U=N-100H-10T$ gives the result you seek with $H$ the hundreds, $T$ the tens, $U$ the units. Then convert $H,T,U$ to binary, probably using a table as there are only ten choices.