誤差
やられた(苦笑
using System; public enum SupportedColors { Mono = 1, Bpp16 = 4, Bpp256 = 8, Bpp4096 = 12, Bpp32768 = 15, Bpp65536 = 16, } public class Program { static void Main() { foreach (int colors in new int[] { 2, 16, 256, 4096, 32768, 65536 }) { SupportedColors col = ToSupportedColors(colors); Console.WriteLine("{0} is {1} (depth {2})", colors, col, (int) col); } } static SupportedColors ToSupportedColors(int colors) { return (SupportedColors) Math.Log(colors, 2); // return (SupportedColors) (int) Math.Log(colors, 2); // return (SupportedColors) Convert.ToInt32(Math.Log(colors, 2)); } } /* Output: 2 is Mono (depth 1) 16 is Bpp16 (depth 4) 256 is Bpp256 (depth 8) 4096 is 11 (depth 11) 32768 is Bpp32768 (depth 15) 65536 is Bpp65536 (depth 16) */