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.
Show HN: How to store a set of four 5-bit values in one 16-bit value
11–20 of 149 posts
Re: Show HN: How to store a set of four 5-bit values in one 16-bit value
#12Re: Show HN: How to store a set of four 5-bit values in one 16-bit value
#13Earlier 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?
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
#14Ah, 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.
Re: Show HN: How to store a set of four 5-bit values in one 16-bit value
#15Re: Show HN: How to store a set of four 5-bit values in one 16-bit value
#16That 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…
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
#17That 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…
Re: Show HN: How to store a set of four 5-bit values in one 16-bit value
#18Ah, 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.
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
#19That 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…
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
#20Earlier 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?