I'm working on a GIF encoder in C# as a spin-off to something else GIF related i was working on.

In the GIF spec there is a "Logical Screen Descriptor" in the header of the file, one of these being how large the global colour table is.

From what i understand the Global Colour Table is anywhere from `0-256`, stored as 3 bits in the format 2(N+1), where N is the decimal value between 1 and 7.

I'm creating a function where i can specify the table size as an integer between 0-256 and then perform a calculation on this to find `N`.

For example, 2(7+1) = 256, how can I get back to 7 from 256?

Ive spent over an hour with a pencil and a sheet of paper trying to remember how to "balance equations" from my time in college but i cant seem to remember...