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?
Last Updated : May 29, 2021

Swift - Create a constant with binary value and print it in decimal number

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.

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

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 »

Advertisement
Advertisement

Related Programs

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

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