I have the number 110111001 (441). I want to extract three numbers from it:
110100000 (416)
000010000 (16)
000001001 (9)
Is there any way I can do this?
I have the number 110111001 (441). I want to extract three numbers from it:
110100000 (416)
000010000 (16)
000001001 (9)
Is there any way I can do this?
On
You can take the number "modulo" some power of two, record that number, then subtract it. And then you can repeat this process.
As an example in base ten, consider the number $n := 46789$.
If I wanted to extract from this 46, 7, and 89, then I would operate as follows:
Compute $d:= n \mod 100$, which will be $89$.
Compute $m := (n-d)/100$, which will be $467$, and return this $\mod 10$, which will be $b := 7$.
Here it is implemented in Desmos:
If you are looking for a bitwise implementation, note that
416 = 441 & (0xf << 5)16 = 441 & (1 << 4)and
9 = 441 & (0xf << 0)can all be obtained by forming a 1 bitmask over continuous digits and shifting.