A hexadecimal value is a value in the number system that is base 16. By default, all values are in the decimal base, that is base 10. In Swift, we create a hexadecimal value by placing 0x
before the digits, we want.
0x(hexadecimalDigit)
0x
: This is the keyword for creating a hexadecimal value in Swift.hexadecimalDigit
: This is the hexadecimal digit we want to use. It can be any of the hexadecimal digits like A
, C
, etc.The value returned by this keyword is a hexadecimal value.
NOTE: When we print the created hexadecimal value to the console, we will get its equivalent decimal value.
// create variables with hexadecimal valueslet hex1 = 0x1;let hex2 = 0xc3;let hex3 = 0x14;let hex4 = 0xAC2;// print the decimal equivalentsprint(hex1)print(hex2)print(hex3)print(hex4)