S
S
Sergey Sokolov2018-06-11 21:28:43
binary code
Sergey Sokolov, 2018-06-11 21:28:43

How to pack in 128 bit values?

You want to set the order of 32 elements with only 128 bits. "Almost" turns out.
Position 0 is one of 32 positions from 0 to 31, 5 bits are required.
The position of the 1st is one of the 31 remaining, 0..30, 5 bits.
...
15: 1 of 16, also 5 bits.
Total already 16 * 5 = 80beat.
16: 1 of 15 positions, 4 bits already.
...
24: 1 of 8, 4 bits.
Total 80 + 4 * 8 = 112bit used.
25: 1 of 7, 3 bits.
...
28: 1 of 4, 3 bits.
Total 112 + 3 * 4 = 124
29: 1 out of 3, 2 bits.
30: 1 of 2, 2 bits.
Total 124 + 4 = 128bit.
There is not enough 1 bit to choose one of the two options at the 31st step.
Is it possible to somehow change the scheme and still put the variant of mixing 32 elements into 128 bits?
The inverse operation of obtaining unique integers 0..31 from a 128-bit array should not require quantum computing, of course.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
longclaps, 2018-06-11
@sergiks

Don't granulate what doesn't need to be granulated.

2^128 = 340282366920938463463374607431768211456
  32! =    263130836933693530167218012160000000

And if you really want to, you can merge 2 inconvenient factors into 1 convenient one, for example
25*5 = 125 < 128
 или
 5*3       <  16

and encode the positions of the 25th from the end (those 8 in your account) bit and the 5th with seven bits.
I haven't tested it, but it might fit.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question