How to format binary representation of RGB colour?

418 Views Asked by At

If I convert, say, #FF$1919$ to binary, I can do it in groups of three bytes like:

FF: $1111$ $1111$

$19$: $0001$ $1001$

$19$: $0001$ $1001$

So can I write that #FF$1919 =$ $1111$ $1111$ $0001$ $1001$ $0001$ $1001$?

Or do I have to write them as separate bytes like above?

2

There are 2 best solutions below

0
On BEST ANSWER

Yes that is absolutely fine. You could have also done it as: $$F: 1111$$ $$F: 1111$$ $$1: 0001$$ $$9: 1001$$ $$1: 0001$$ $$9: 1001$$ and combined in the same way

So $FF1919: 1111\space 1111\space 0001\space 1001\space 0001\space 1001$

0
On

Yes, the positional systen works as expected: $$ (FF1919)_{16} = 15 \cdot 16^5 + 15 \cdot 16^4 + 1 \cdot 16^3 + 9 \cdot 16^2 + 1 \cdot 16^1 + 9 \cdot 16^0 \\ $$ Then we have $$ 16^k = (2^4)^k = 2^{4k} $$ so \begin{align} (FF1919)_{16} &= (1111)_2 \cdot 2^{4\cdot 5} + (1111)_2 \cdot 2^{4\cdot 4} + (0001)_2 \cdot 2^{4\cdot 3} + (1001)_2 \cdot 2^{4\cdot 2} + \\ & \quad \, (0001)_2 \cdot 2^{4\cdot 1} + (1001)_2 \cdot 2^{4\cdot 0} \\ &= 1\cdot 2^{23} + 1\cdot 2^{22} + 1\cdot 2^{21} + 1\cdot 2^{20} + 1\cdot 2^{19} + \dotsb \\ & \quad \, 1\cdot 2^{3} + 0\cdot 2^{2} + 0\cdot 2^{1} + 1\cdot 2^{0} \\ &= (1111 \, 1111 \, 0001 \, 1001 \, 0001 \, 1001)_2 \end{align}