public static void main(string[] args) { ulong[] bounds = new ulong[] { PACKED_1_START, PACKED_1_END, PACKED_2_START, PACKED_2_END, PACKED_3_START, PACKED_3_END, PACKED_4_START, PACKED_4_END, PACKED_5_START, PACKED_5_END, PACKED_6_START, PACKED_6_END, PACKED_7_START, PACKED_7_END, }; for (int n = 0; n < bounds.Length; n++) { for (ulong l = bounds[n] - 1; l < bounds[n] + 2; l++) { long abs = Math.Abs((long)l); Console.WriteLine(String.Format("number {0} {1} {2} bits: {3} switch: {4} - {5}" , l.ToString("X") , l , Fns.numberOfLeadingZeros(abs) , bitsneeded((long)l) , switchon((long)l) , abs)); } } }
public static int switchon(long l) { if (l > 0) { return(Fns.numberOfLeadingZeros(l)); } else { return(Fns.numberOfLeadingZeros(~l)); } }
public static int bitsneeded(long l) { if (l > 0) { return(65 - Fns.numberOfLeadingZeros(l)); } else { return(65 - Fns.numberOfLeadingZeros(~l)); } }