I
I
Ilya2020-11-24 17:19:26
Python
Ilya, 2020-11-24 17:19:26

How to build a function to decode the classic Elias code if the direct encoding works correctly?

Hello everyone, Elias's classic code's direct encoding function is OK, everything works:

return (int(log(int(log(number,2)),2))*'0'+' '+str(bin(int(log(number,2))+1))[2:]+' '+str(bin(number)[3:]))

but I don’t know how to do the opposite .. conditionally from 000100110001110 to 398. Help me out)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2020-11-24
@wataru

Describe in words what this encoding does, what does it write to the file?
And read this:
1) count how many zeros go at the beginning of the string.
2) This is how many bits you need to read further and translate into a decimal number system.
3) This is as many bits as you need to read further and convert to the decimal system in order to decode the number.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question