# convert from binary to hexadecimal according to the algorithm "keeloq"

Good afternoon. I have the key to my gate. I received its recording in the form of a PWM pulse train. Instead, I converted the impulses into binary code. Now I should get the hex numbers but it doesn't converge.

I have the same sequence in hexadecimal. How to translate correctly? I know that you need to read from the least significant bit. I selected 4 characters each and highlighted in different colors for convenience

it should turn out like this:

• Your sequence looks like it may be bit-inverted and byte reversed e.g. inverting and reversing 1101 1111 gives you 0000 0100 which is the binary equivalent of 04 Commented Jun 28, 2022 at 15:15
• Wow! Excellent! Thank you so much, I wouldn't have guessed! Commented Jun 29, 2022 at 2:18

$$\begin{matrix} 1101 \ 1111 \ 1101 \ 1101 & \rightarrow& \mbox{inverted, bit reversed} & \rightarrow& \tt 0x04 \ 0x44\\ 0001 \ 0111 \ 0001 \ 0111 & \rightarrow& \color{red}{\mbox{straight, no reverse}} &\rightarrow& \tt 0x17 \ 0x17\\ 0110 \ 0111 \ 1101 \ 0010 & \rightarrow& \mbox{inverted, bit reversed} & \rightarrow& \tt 0x19 \ 0xB4\\ 0000 \ 0001 \ 1101 \ 1101 & \rightarrow& \mbox{inverted, bit reversed} & \rightarrow& \tt 0x7F \ 0x44\\ 00 \rightarrow \color{green}{???}& \end{matrix}$$