1
$\begingroup$

I am learning Computer Architecture from Introduction to Computing Systems (2nd Edition) and am stuck on this question.

What operations can be used to convert the binary representation of 3 into ASCII representation for 3? What about binary 4 to ASCII or any other digit?

The concepts I have learnt until now are Basic Logic gates and Bit Masking so I have to use them for conversion. Can someone help me understand what my approach should be?

$\endgroup$
3
$\begingroup$

By looking at a ASCII table you can see that the $4$ least significant bits of all characters between $0$ and $9$ correspond to the respective integer representations of the numbers between $0$ and $9$, while the 4 most significant bits are always $0011$ (leading zeroes are not shown in the table, so keep in mind you need to pad binary numbers to 8 bits).

If $x$ is the binary representation of a number between $0$ and $9$, you can then obtain the ASCII representation of the corresponding character as $$ x \;| \;00110000, $$

where $|$ denotes a bitwise logical or and the second operand is in binary.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you so much, I understood this. The ASCII representation of the numbers was in seven bits and the mask was six bits. So in order to avoid confusion, I converted both to 8 bits. Can you please edit your answer so that another student who sees the answer doesn't get confused? $\endgroup$ – Aryan May 31 at 0:50
  • $\begingroup$ I clarified my answer :) $\endgroup$ – Steven May 31 at 2:10
  • $\begingroup$ Thank you so much! $\endgroup$ – Aryan May 31 at 3:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.