Q:

Swift program to create a constant with binary 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 with binary number by using '0b' 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 binary 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 binary value
// and print it in decimal number

let num = 0b11001111;

print("Decimal number: ",num);

Output:

Decimal number:  207


...Program finished with exit code 0
Press ENTER to exit console.

Explanation:

Here, we created a constant num using the let keyword initialized with binary number 0b11001111. 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 a constant with hexadecima... >>
<< Swift program to create a constant...