Recently I had to implement this problem in c#, and thought it would make for a good code golf.
Your goal is to output the smallest unsigned data-type a 64 bit unsigned number can fit into.
Input: An unsigned 64-bit number (or the closest builtin equivalent in your chosen language)
Output: A number representing the bytes of the smallest unsigned data-type the input value can fit into (1, 2, 4, or 8)
Data Type Max Values:
byte => 255
ushort => 65535
uint => 4294967295
ulong => 18446744073709551615
Examples:
0 => 1 (byte)
255 => 1 (byte)
256 => 2 (ushort)
500 => 2 (ushort)
60000 => 2 (ushort)
4294967295 => 4 (uint)
4294967296 => 8 (ulong)
18446744073709551615 => 8 (ulong)
This can be done using lzcnt, if statements, regex, bit manipulation, etc. (creative solutions & languages encouraged!)
This is a code-golf, so shortest solution wins!