C
C
cup_of_sugar2020-07-07 10:48:30
Mathematics
cup_of_sugar, 2020-07-07 10:48:30

Is it possible to encode some number of digits into less?

For example, is it possible to encode 11 digits into 9 and then decode them? Personally, this seems impossible to me (each digit carries a certain amount of information and it will not be possible to refuse it), but maybe there are some tricky algorithms.

Answer the question

In order to leave comments, you need to log in

6 answer(s)
L
Lynn "Coffee Man", 2020-07-07
@Lynn

There is such a science - mathematics.
She says that one cannot map 10^11 values ​​to 10^9 one-to-one.

R
Rsa97, 2020-07-07
@Rsa97

11 digits [0-9] to 9 digits [0-9] is not possible.
And 11 digits [0-9] into 9 characters [0-9a-zA-Z] is easy.

E
evgeniy_lm, 2020-07-07
@evgeniy_lm

Can. Change the number system to a higher one and you will be happy. For example, the number 99 999 999 999 (10) is the same as 247BAFB5E (17)

A
Adamos, 2020-07-07
@Adamos

The question is incorrect.
In the general case, if the information is chaotic, it is impossible to reduce its volume.
In specific cases, it often has some order that can be used to replace this information with the logic by which it can be re-created. This is how archivers work, for example.

R
Roman Mirilaczvili, 2020-07-07
@2ord

If each digit is represented by one byte of the ASCII table, then it can be encoded into fewer bytes .
For example, let's take the number 12345678901. It has 11 digits. If we represent each digit with the corresponding ASCII table code (Ruby code)

n=12345678901
n.to_s.each_codepoint {|c| print c, ' ' }

We get the output of the sequence
49 50 51 52 53 54 55 56 57 48 49 => "12345678901"
That is, the sequence is not optimally stored in memory.
Now let's see how the number looks like as a sequence of bits:
puts n.to_s(2)  # конвертация в строку по двоичной системой счисления

Conclusion:
1011011111110111000001110000110101
Too lazy to count manually: We got the number 34. 34 = 4 * 8 + 2 That is, 4 whole bytes and 2 bits. The actual size of the sequence to store in memory is 5 bytes. That is, 11 bytes of a number are represented by 5 bytes. Conclusion:
puts n.to_s(2).size
bytes = [n].pack('w') # кодирование числа в BER.
=> "\xAD\xFE\xF0\xB85"

V
Vyacheslav Shindin, 2020-07-16
@pro_co_ru

https://ru.wikipedia.org/wiki/%D0%9A%D0%BE%D0%B4_%...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question