Get the latest tech news

Bit-twiddling abstract addition with unknown bits (2020)


(If you can’t read the code in this post on mobile, try this wrapped version instead, sorry) Suppose you have two values. You know some bits are zero, some bits are one, other bits could be e…

I could also store a third value, “known zeroes”, but this can be calculated if needed by the expression~(v.ones | v.unknowns), and it seemed error prone to make the representation more redundant. This has an exponential runtime, so it’s entirely impractical, but I quite like it as a mathematical definition of the best possible result, and it can be useful for quickly testing better algorithms. The(a.ones + b.ones) expression now appears in three places, so we calculate it ahead of time to simplify things, giving the function shown at the top.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Bit

Bit

Photo of unknown bits

unknown bits

Related news:

News photo

How many photons are received per bit transmitted from Voyager 1?

News photo

Larian Studios' CEO says, "we did have to do a bit of crunch" making Baldur's Gate 3

News photo

Good news: The iPad Pro 13 is a bit more repairable