Q:

Swift program to create a constant with hexadecimal value and print it in decimal number

belongs to collection: Swift Basic Programs

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

// 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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Swift Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Swift program to create an alias of basic types... >>
<< Swift program to create a constant with binary val...