Binary Converter using Python

Did You Know?

Everything that is stored on a computer is stored as binary code. Binary code is made of bits (0 or 1). We often use Bytes to store data. A Byte is made of eight bits and can be used to store any whole number between 0 to 255. Check it yourself, click on the binary digits to create your own binary number:

1286432168421
11111111

128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255


Python Challenge


The purpose of this challenge is to write a Python script to convert a Binary number into denary and vice versa. To do so we will use the concept of binary left and right shifts as explained below.

Binary Left Shift


A binary left shift is used to multiply a binary number by two. It consists of shifting all the binary digit to the left by 1 digit and adding an extra digit at the end with a value of 0.
binary-left-shift

Binary Right Shift


A binary right shift is used to divide a binary number by two. It consists of shifting all the binary digit to the right by 1 digit and adding an extra digit at the beginning (to the left) with a value of 0.
binary-right-shift

Python Code



unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 3.6 / 5. Vote count: 17

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: ,