Convert binary to decimal Pep 8?

I don't know how widespread use of Pep 8 is, but here goes anyways: how do you convert a three digit binary number into a decimal?

Here is my code:

49 00 30

49 00 31

49 00 32

D1 00 31

1C

F1 00 31

D1 00 32

1C

F1 00 32

D1 00 30

71 00 31

71 00 32

F1 00 30

51 00 30

zz

I input three separate characters then shift to the left once the second character and to the left twice the first character, then I add them all together. I am not sure how to debug in this language, so I'm having trouble finding the mistake, especially since though input works, I get no output.

-15213 Accumulator

39 Program Counter

Comments

  • Each bit of a binary number is 2^n from least significant (probably right most) to most significant. So 111 is actually 2^2+2^1+2^0=4+2+1

    You can calculate by creating a bit shifting for loop from 0 to the length of your binary number. At each iteration, check to see if the least significant bit is 1 or 0. If 1, then add 2^i (where i is your current for loop index) to a running sum. At the end of each iteration, shift your target binary right 1 place.

Sign In or Register to comment.