# any binary dopers out there?

**URL:** <https://boards.straightdope.com/t/any-binary-dopers-out-there/53841>\
**Category:** Factual Questions\
**Created:** [February 9, 2001, 9:39pm UTC](https://boards.straightdope.com/t/any-binary-dopers-out-there/53841 "2001-02-09T21:39:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lask](https://avatars.discourse-cdn.com/v4/letter/l/76d3ee/32.png) [@lask](https://boards.straightdope.com/u/lask)\
**Post date:** [February 9, 2001, 9:39pm UTC](https://boards.straightdope.com/t/any-binary-dopers-out-there/53841/1 "2001-02-09T21:39:26Z")

</div>

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 3_10^0 and that the breakdown in binary is 1_2^0 + 1\*2^1 so where do I go from here??

Any takers?

---

<div class="post-metadata">

**Author:** ![Arjuna34](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@Arjuna34](https://boards.straightdope.com/u/Arjuna34)\
**Post date:** [February 9, 2001, 9:56pm UTC](https://boards.straightdope.com/t/any-binary-dopers-out-there/53841/2 "2001-02-09T21:56:27Z")

</div>

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 😉

Arjuna34

---

<div class="post-metadata">

**Author:** ![LazarusLong42](https://avatars.discourse-cdn.com/v4/letter/l/87869e/32.png) [@LazarusLong42](https://boards.straightdope.com/u/LazarusLong42)\
**Post date:** [February 9, 2001, 11:27pm UTC](https://boards.straightdope.com/t/any-binary-dopers-out-there/53841/3 "2001-02-09T23:27:54Z")

</div>

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.)

LL

---

<div class="post-metadata">

**Author:** ![lask](https://avatars.discourse-cdn.com/v4/letter/l/76d3ee/32.png) [@lask](https://boards.straightdope.com/u/lask)\
**Post date:** [February 10, 2001, 12:30am UTC](https://boards.straightdope.com/t/any-binary-dopers-out-there/53841/4 "2001-02-10T00:30:10Z")

</div>

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