News for hackers. Stuff that matters.
Re:Do binary files contain more 1s or 0s? by jeltz on Tuesday November 12, 2019 @03:35PM (#21517876)
The bug is that

    bin(decimal)[2:]
should be

    bin(decimal)[2:].rjust(8, '0')
or else the leading zeros are not counted.

Personally I would probably have used shift for a simple script like this.

Re:Do binary files contain more 1s or 0s? by joezydeco on Tuesday November 12, 2019 @03:38PM (#21517901)
Or a 255-entry precomputed lookup table.
Re:Do binary files contain more 1s or 0s? by fla on Tuesday November 12, 2019 @03:41PM (#21517945)
256 entries
Re:Do binary files contain more 1s or 0s? by joezydeco on Tuesday November 12, 2019 @03:43PM (#21517970)
You can skip the lookup on a zero and do the dereference on a non-zero value.
Re:Do binary files contain more 1s or 0s? by fla on Tuesday November 12, 2019 @03:47PM (#21518015)
You can, but that’ll cost you one extra branch, for nothing ;)
Re:Do binary files contain more 1s or 0s? by joezydeco on Tuesday November 12, 2019 @04:46PM (#21518512)
Sorry, was coming from an ARM perspective. Conditional execution is fun.