any binary dopers out there?

I’m working on an assembler homework assignment. The question entails reading in a string of numbers of length 6 and converting it into the 2’s complement (binary) representation.
There’s a hint: Find an arithmetic operation that would convert an ASCII representation of a number (ex. ‘3’) to a binary representaton of the same number (ex. 0011).
I know that the breakdown of 3 in decimal is 310^0 and that the breakdown in binary is 12^0 + 1*2^1 so where do I go from here??

Any takers?

If the ascii representation of a digit is stored in a register, just subtract the number 48 from it to turn it into a binary number in the register. Since ascii for zero is 48, one is 49, etc. this converts the digit from ascii to binary.

Your on your own for converting the six decimal digits into a 20-bit binary number :wink:


Call your number of six digits A.

A MOD 2 is the last digit of the binary representation of your number.

B := INT (A/2). B MOD 2 is the next to last binary digit.

C := INT (B/2). C MOD 2 is the third to last digit.

…I think you can see where this is going.

(Isaac Asimov discussed this method of quickly converting decimal to binary in an article entitled “One, Ten, Buckle My Shoe,” which was also reprinted in the book Asimov on Numbers. Highly recommended.)


Thanks LL,
That’s a neat algorithm. Now if I can figure out the rest…