Live data from Hacker News

Show HN: How to store a set of four 5-bit values in one 16-bit value

github.com

11–20 of 149 posts

Re: Show HN: How to store a set of four 5-bit values in one 16-bit value

#11
post #6
post #2

Ah, without preserving order. That's a set of four 5-bit values, not a sequence of four 5-bit values.

To answer the obvious next question: Four 5-bit values in order have 20 bits of entropy, so cannot be stored in 16 bits. Four 5-bit values without order have 20 - log2(4!) =~ 20 - 4.59 = 15.41 bits of entropy (corresponding to log(2^20/4!) possible configurations), and thus can fit in 16 bits of data if you're clever about it.

Is there a specific topic of study that taught you those formulas?

Re: Show HN: How to store a set of four 5-bit values in one 16-bit value

#13
post #6

Earlier quoted context omitted.

To answer the obvious next question: Four 5-bit values in order have 20 bits of entropy, so cannot be stored in 16 bits. Four 5-bit values without order have 20 - log2(4!) =~ 20 - 4.59 = 15.41 bits of entropy (corresponding to log(2^20/4!) possible configurations), and thus can fit in 16 bits of data if you're clever about it.

Is there a specific topic of study that taught you those formulas?

Not the person you asked but

4! is the number of permutations of a list - it's commonly seen throughout CS theory and other forms of discrete math.

log_2(n) is the number of bits needed to store a integer from 0 to n - it's reasonably commonly used in CS theory education.

Re: Show HN: How to store a set of four 5-bit values in one 16-bit value

#14
post #7
post #2

Ah, without preserving order. That's a set of four 5-bit values, not a sequence of four 5-bit values.

Hmm, it's interesting to me that order would be expected. I nearly always think of storage and ordering as entirely separate problems.

Usually, when you store a value, you want to be able to get exactly that value back. If you store multiple values without keeping the ordering, you lose that capability. I.e. you can't replace all possible uses of four 5-bit variables with one 16-bit variable, only those where the variables are interchangeable.

Re: Show HN: How to store a set of four 5-bit values in one 16-bit value

#15
post #8

This is quite related to the problem of sorting a million 32 bit integers using only 2M of RAM (and no disk). It can be done.

Only if all your ints are unique I guess?

No, that's not a requirement, as it turns out, though of course it would decrease the entropy even further.

Re: Show HN: How to store a set of four 5-bit values in one 16-bit value

#16

That is one big-ass makefile though. I realize it has some extra niceties but I have to ask, did you ever try make main without any makefile at all? If you haven't done so, delete the makefile now (you have it in version control anyway) and give it a try.

GNU Make has a number of implicit rules. A blank target rule (or no target rule) in the Makefile (or no Makefile at all!) will cause `make` to try to create the specified target `foo` from `foo.c` or `foo.cpp` (or others) if they exist. More complete explanation here: https://www.gnu.org/software/make/manual/html_node/Catalogue... Note: I was initially annoyed with parent's "do this and see what happens" post and its…

> self-impressed and coy

That's an odd thing to read into my comment. I am merely passing on information that was at one point given to me when I myself had a Makefile that was actually not needed because the program it was for was a single source file project like OP.

Also in what way is it easier to read a long document without reference to a specific section than it is to just delete the makefile and run make and the stem of the name of the source file?

Edit: My second paragraph of this comment was written prior to parent commenter editing their comment.

Re: Show HN: How to store a set of four 5-bit values in one 16-bit value

#17

That is one big-ass makefile though. I realize it has some extra niceties but I have to ask, did you ever try make main without any makefile at all? If you haven't done so, delete the makefile now (you have it in version control anyway) and give it a try.

GNU Make has a number of implicit rules. A blank target rule (or no target rule) in the Makefile (or no Makefile at all!) will cause `make` to try to create the specified target `foo` from `foo.c` or `foo.cpp` (or others) if they exist. More complete explanation here: https://www.gnu.org/software/make/manual/html_node/Catalogue... Note: I was initially annoyed with parent's "do this and see what happens" post and its…

I appreciate that you edited your comment to make it more informative. Now if you could also remove the snark, it would be a great comment.

Re: Show HN: How to store a set of four 5-bit values in one 16-bit value

#18
post #6
post #2

Ah, without preserving order. That's a set of four 5-bit values, not a sequence of four 5-bit values.

To answer the obvious next question: Four 5-bit values in order have 20 bits of entropy, so cannot be stored in 16 bits. Four 5-bit values without order have 20 - log2(4!) =~ 20 - 4.59 = 15.41 bits of entropy (corresponding to log(2^20/4!) possible configurations), and thus can fit in 16 bits of data if you're clever about it.

Your math is wrong.

If two of the numbers happen to be the same, order no longer matters for those numbers, so your log2(4!) needs to be larger...

Re: Show HN: How to store a set of four 5-bit values in one 16-bit value

#19

That is one big-ass makefile though. I realize it has some extra niceties but I have to ask, did you ever try make main without any makefile at all? If you haven't done so, delete the makefile now (you have it in version control anyway) and give it a try.

GNU Make has a number of implicit rules. A blank target rule (or no target rule) in the Makefile (or no Makefile at all!) will cause `make` to try to create the specified target `foo` from `foo.c` or `foo.cpp` (or others) if they exist. More complete explanation here: https://www.gnu.org/software/make/manual/html_node/Catalogue... Note: I was initially annoyed with parent's "do this and see what happens" post and its…

Your response of linking the GNU Make manual comes of as even more self-impressed and coy than the parent.

The parent suggests removing the makefile entirely and running `make main`, and observing the result. That would be a learning experience (and much better than your "RTFM")! But, if you don't want to humor that, the thing to say is: The result is that it works, and correctly builds the program, without a makefile at all.

The explanation is that GNU Make has a catalog of built-in rules (which you linked to); but it's quite a leap from knowing that fact, and even making use of them, to realizing that it means in some cases you don't need a makefile at all.

Re: Show HN: How to store a set of four 5-bit values in one 16-bit value

#20
post #6

Earlier quoted context omitted.

To answer the obvious next question: Four 5-bit values in order have 20 bits of entropy, so cannot be stored in 16 bits. Four 5-bit values without order have 20 - log2(4!) =~ 20 - 4.59 = 15.41 bits of entropy (corresponding to log(2^20/4!) possible configurations), and thus can fit in 16 bits of data if you're clever about it.

Is there a specific topic of study that taught you those formulas?

Probability theory and information theory.
Post reply on HN