Skip to content

A little script to "manually" convert a decimal numer into a binary one and vice versa

Notifications You must be signed in to change notification settings

Annika-Klu/binary-converter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

binary-converter

Reading the book "Code" by Charles Petzold - which btw is a good read! - inspired me to write this script: it converts a decimal numer into a binary one and vice versa.

In the conversion of the binary number, the counter value of the iteration is used both for indexing through the binary number, as well as calculating the power of 2 we are dealing with at each position of the number. The number in the leftmost position holds the lowest index number, but the highest power of 2. In the first solution, I reversed the binary number before iterating. Now, I've refactored the code, starting my index at pos. 0 when iterating, but using reverse indexing when calculating powers of 2.

About

A little script to "manually" convert a decimal numer into a binary one and vice versa

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published