# How binary is converted and print on screen/Binary integer to Screen 'ASCII' integer conversion

5 messages
Open this post in threaded view
|

## How binary is converted and print on screen/Binary integer to Screen 'ASCII' integer conversion

 This post was updated on . Hi guys, I have a question about printing binary data on the hack computer screen. Let's say a int type data: 0000000011111111 (decimal 255) is stored in an address of the hack computer memory. When i use Output.printInt() to show the data on the screen, it is totally fine 255 is printed. But my question is how this is implemented? How Output.printInt() convert binary integer stored in the memory to correct ascii representation (decimal) of the integer? I have completed Output,String,Array class, but i still don't get how integer stored in the memory can be printed on the screen.       Could anyone please share/explain your understanding with me? Thanks a lot peter
Open this post in threaded view
|

## Re: How binary is converted and print on screen/Binary integer to Screen 'ASCII' integer conversion

 The conversion is implemented in String.setInt and is described quite well in the book. The only thing you need to figure out is how to convert a single digit number to its corresponding character. Hint: characters in Jack are also represented as numbers.
Open this post in threaded view
|

## Re: How binary is converted and print on screen/Binary integer to Screen 'ASCII' integer conversion

 This post was updated on . Hi ivant, Thanks for replying my question. Yes, I see the String.setInt() convert decimal to string, then print on the screen using stored ascii array bit map.  But my question is how binary data stored(binary representation of integer) in the memory is converted to decimal data (ascii representation of the integer). Same example here: 0000000011111111 (decimal 255)  ->  110010(0x32/50) 110101(0x35/53) 110101(0x35/53) [Ascii representation of decimal 255 in binary]. So when the hack computer check the memory location which contains 0000000011111111 (decimal 255), i think some conversion are needed to be done in order to find  [Ascii representation of decimal 255 in binary], then use the stored bit map to print the corresponding shape of the number on the screen. After some search online, I realize if there is an additional hardware/software required to convert binary to bcd(binary coded decimal), then use bcd representation to find corresponding bit map of each integer and showing on the screen. Thanks Peter