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

Here, we are going to learn how to create a constant with binary value and print it in decimal number in Swift programming language?
Submitted by Nidhi, on May 29, 2021

Problem Solution:

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.

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.

Swift Basic Programs »



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.