1
votes

I am in a CSCI class and we are just learning about program execution. I am running a program called "Brookshear machine simulator" which was written by the author of the class text book ( Computer Science 11th edition by J. Glenn Brookshear). The program is intended to add the contents of 11 and 0F, storing the result into F1. I have done everything necessary and produced the hex value in 11 which is 09. I am then asked to convert this into two's complement 8-bit binary, which is where I am having a problem. I will be needing to convert some hex values into two's compl 8-bit binary in the future for this lab but I cant figure out how to do it. Can someone please help me understand what twos comp is and how is it related or the same as 8-bit binary , so I can convert this to two's complement 8-bit binary? Here is a picture of the machine simulator with the inputs as directed by the lab instructions. My task is to find the hex value in 11 (09) then convert it to twos complement 8-bit binary.

Here is a picture of the machine simulator with the inputs as directed by the lab instructions. My task is to find the hex value in 11 (09) then convert it to twos complement 8-bit binary.

1

1 Answers

2
votes

Each hexadecimal digit has a 4 bit binary equivalent:

0  0000
1  0001
2  0010
3  0011
4  0100
5  0101
6  0110
7  0111
8  1000
9  1001
A  1010
B  1011
C  1100
D  1101
E  1110
F  1111

So if you have a two character hex value, like 09 then you can see that 0 = 0000 and 9 = 1001, so that would be:

00001001

which is an 8 bit value.

This works for any length of hex number of course, so for example 37FF in hex would be 0011011111111111 in binary.

Note that two's complement is irrelevant for your example as the number is positive.