Here, we will create a constant using the let keyword and initialize it with hexadecimal numbers by using "0x" in the prefix of the number. Then print the corresponding decimal value using the print() function on the console screen.
The source code to create a constant with hexadecimal value and print it in a decimal number is given below. The given program is compiled and executed successfully.
// Swift program to create a constant with hexadecimal value
// and print it in decimal number
let num = 0x30;
print("Decimal number: ",num);
Output:
Decimal number: 48
...Program finished with exit code 0
Press ENTER to exit console.
Explanation:
Here, we created a constant num using the let keyword initialized with hexadecimal number 0x30. Then we printed the corresponding decimal number on the console screen.
Program/Source Code:
The source code to create a constant with hexadecimal value and print it in a decimal number is given below. The given program is compiled and executed successfully.
Output:
Explanation:
Here, we created a constant num using the let keyword initialized with hexadecimal number 0x30. Then we printed the corresponding decimal number on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer