You need to convert the value to hexadecimal, and then flip the first two digits with the last two. For example, converting a raw value of 16711680 to blue gives the hexadecimal value of FF0000. However, the value for blue is 0000FF; swap required (so yes, another answer is wrong ...)
The value is also supplemented to always have 6 required digits.
string rawHex = msAccessColorCode.ToString("X").PadLeft(6, '0'); string hexColorCode = "#" + rawHex.Substring(4, 2) + rawHex.Substring(2, 2) + rawHex.Substring(0, 2);
To do the opposite (hex β Ms Acces), simply follow the steps in reverse. Discard the extra character # , discard the first / last two values ββand convert this number from base 16 to base 10.
string input = "#0000FF"; string hexColorCode = input.TrimStart('#'); string rawHex = hexColorCode.Substring(4, 2) + hexColorCode.Substring(2, 2) + hexColorCode.Substring(0, 2); string result = Convert.ToInt32(rawHex, 16).ToString();
Please note that Intew.Max set to 0x7FFFFFFF (and our color codes close at 0xFFFFFF ), so it is completely safe to use Convert.ToInt32 here instead of Int64 .
source share