Computer Architecture Homework 3

Ed Smart

CSC 320

Homework 3

3.1 The following table shows pairs of octal numbers.

.                           A                           B

a.                      3174                       0522

b.                      4165                       1654

3.1.1 What is the sum of A and B if they represent  unsigned 12-bit octal numbers? The result should be written in octal.

a.        3174

+        0522

—————-

.         3716

The sum of the octal numbers 3174 and 0522 is 3716. First, 4 and 2 are added, giving a result of 6 in the ones place. Next, 7 and 2 are added. Since the numbers are in octal (base 8), they cannot simply give a sum of 9 as they would in decimal (base 10) since single digits in octal cannot exceed 7, the same way they cannot exceed 9 in decimal. If the problem was in decimal numbers and the 7 in 3174 was changed to a 9, once it was added to the 2 in 0522’s tens place, it would result in a 1 with 1 being carried over to the hundreds place. The same concept applies in octal. Since these numbers are in octal, when 2 is added to 7 (summing to 9), 8 is reached, so a 1 is carried over to the hundreds column and the remaining 1 left over (9-8=1) is placed in the tens place. The 1 carried over from the tens column is then added to the 1 in 3174, which is then added to the 5 in 0522 (1+1+5=7). Finally, 3 is added to 0, giving a final sum of 3716.

b.        4165

+         1654

—————–

.          6041

The same concepts explained in answer a are used here. 5 and 4 are added first, resulting in 9, so a 1 is carried to the tens column and the remaining 1 is put in the ones place. Then, 6 and 5 are added to the carried 1, giving 12 (1+6+5=12), so a 1 is carried to the hundreds column and the remaining 4 (12-8=4) is placed in the tens place. Next, the 1 and 6 are added along with the carried 1 from the tens column, giving 8 (1+1+6), so a 1 is again carried and 0 is put in the hundreds place. Finally, the carried 1 is added to 4 and 1, resulting in 6 (1+4+1=6), which is placed in the thousands.

There are a number of other approaches to this problem, such as converting the numbers to other formats, solving the equations, and the results back into base 8. For example, you could convert the numbers to base 10, add them, then convert the sum back to base 8.

First, in order to convert a number from base 8 to base 10, pick the highest power of 8 that is less than the number to be converted. Then, starting from the leftmost digit of the number, multiply each digit by descending powers of 8. Finally, add all of the quantities together. The resulting sum is the decimal form of the original octal number.

For example, to convert 8^^3174 to base 10:

8^3=512   #Highest power of 8 less than 3174

(3*8^3=1536) + (1*8^2=64) + (7*8^1=56) + (4*8^0=4)                                                                                                                                                              #Multiply each digit in 3 1 7 4 by a corresponding power of 8, in descending order

1536 + 64 + 56 + 4 = 1660     #8^^3174 = 10^^1660

And then the same is done to convert the second octal number, 0522:

8^3 = 512

(0*8^3) + (5*8^2) + (2*8^1) + (2*8^0)

0       +       320    +     16     +      2        =        338

8^^0522 = 10^^338

Then, the decimal values are added for part a:

a.   8^^3174      =     10^^1660

+   8^^0522      =     10^^0338

—————-             —————

.                                    1998

And now to convert 1998 from base 10 back to base 8. To do this, divide 1998 by 8. Record the remainder and divide the rest of the quotient again by 8. Repeat this process, while recording the remainders, until a quotient that is less than 8 is reached. Once this point is reached, list all of the remainders and add the final quotient (which is less than 8) to the end of the list. Then, simple read the list backward. This is the base 8 version of 1998.

1998 / 8 = 249, r6

249 / 8 = 31, r1

31 / 8 = 3, r7

3 < 8

10^^1998 = 8^^3716

As you can see, this approach gives the same result as the first one used.

If the same  method is applied to part b, the first step is to again convert the octal numbers to decimal. Starting with 4165:

8^4 = 4096

(0*8^4) + (4*8^3) + (1*8^2) + (6*8^1) + (5*8^0)

.     0    +  2048    +    64     +    48    +     5    =    2165

8^^4165 = 10^^2165

Then the same is done for the second number, 1654:

8^3 = 512                                      #Again  8^3 is used, as it is the highest power of 8 that is less than the octal number to be converted

(1*8^3) + (6*8^2) + (5*8^1) + (4*8^0)

512    +      384     +   40     +     4    =   940

8^^1654 = 10^^940

b.  8^^4165          =        10^^2165

+   8^^1654          =        10^^0940

—————-                   —————

.                                          3105

10^^3105 is then converted to base 8, since the question asks for the sum to be in octal.

3105 / 8 = 388, r1

388 / 8 = 48, r4

48 / 8 = 6, r0

6 < 8

10^^3105 = 8^^6041

Again, this approach gives the same result as the first approach.

Another approach would be to convert the octal numbers to binary and then convert the sum back to octal after the addition is performed. First, the numbers must be converted from octal to binary. This is done by simply converting each digit in the number into its binary counterpart. For example:

3 1 7 4 in octal = 011 001 111 100 in binary

a.     8^^3174           =                 2^^011001111100

+   8^^0522             =                 2^^000101010010

——————                            —————————

.                                                     011111001110

Then, the binary sum must be converted back to octal. 011 111 001 110 in base 2 = 3 7 1 6 in base 8, or 3716.

b.    8^^4165        =       2^^100001110101

+  8^^1654           =       2^^001110101100

——————               ————————–

.                                        110000100001

2^^110000100001 = 8^^6041

As you can see, the result of this method is the same as shown in the previous methods.

3.1.2 What is the sum of A and B if they represent signed 12-bit octal numbers stored in sign-magnitude format? The result should be written in octal.

.              A                      B

a.         3174               0522

b.        4165                1654

If the octal numbers are converted into signed 12-bit binary numbers stored in sign-magnitude format:

a.

8^^3174  = 2^^011 001 111 100

8^^0522 = 2^^000 101 010 010

The most significant bit (leftmost bit) in a signed binary number is the sign bit, which determines whether the number is positive or negative. This means that the bit is no longer a part of the numbers that the operation is being performed on, but rather serves as a sign.If the bit is a 0, the number is positive. If the bit is a 1, the number is negative. As you can see, both of the above numbers are positive as they both have a 0 in the sign bit.

.         8^^3174       =           2^^011 001 111 100

+       8^^0522       =           2^^000 101 010 010

——————-                 —————————–

.                                           011 111 001 110

The binary sum must then be converted to octal:

2^^011111001110 = 8^^3716

b.

8^^4165 = 2^^100 001 110 101

8^^1654 = 2^^001 110 101 100

Part b is approached in a similar fashion. Notice, however, that when 4165 is converted from base 8 to base 2, the most significant bit (or sign bit, in the case of sign-magnitude format) is a 1 this time because the leading 4 is represented as 100 in base 2. As mentioned earlier, this means that the number is negative, while 1654 remains positive when converted to base 2. This means that the operation is adding a negative number to a positive one. In other words, subtracting.

Due to the fact that the most significant bit in 100001110101 is serving as the sign bit, it is excluded from the actual value of the number. And since the other 2 bits that combine with it to form the leading digit 100, or 4, are both zeros, the first digit in 4165 in this case is now 0, making the new octal number -0165.

Thus, the equation for the sum is written in octal numbers as:

.         1654

.      – 0165

————-

.         1467

3.1.3 Convert A into a decimal number, assuming it is unsigned. Repeat assuming it stored in sign-magnitude format.

.           A                B

a.      3174          0522

b.      4165         1654

a. So, the first octal number to be converted into decimal, assuming it to be unsigned, is 3174.

In order to convert 8^^3174 to base 10, the highest power of 8 that is less than 3174, 8^3, is multiplied by the first digit in 3174, the 3. Similarly, the rest of the digits in the number 3174 are each individually multiplied by powers of 8 in descending order until the last digit in the octal number is multiplied by 8^0. All of the resulting quantities are then added together. The sum of these quantities is the decimal version of the octal number originally presented. So, the process looks like this:

8^3 = 512        #Highest power of 8 less than 3174

.    (3*8^3) + (1*8^2) + (7*8^1) + (4*8^0)           #Octal digits multiplied by descending powers of 8

.      1536    +     64         +       56      +      4     =    1660         #Quantities are summed for final result

8^^3174 unsigned = 10^^1660

b. The same method is applied for part b. Here, the octal number to be converted to decimal is 4165. Again, the first step is to find the highest power of 8 that is less than the octal number to be converted, 4165, in this case. This time, that happens to be 8^4 (4096). However, using the method used in the previous problem, you will notice that, since 8^4 is being used here, the number 4165 basically runs out of digits with which to multiply powers of 8, as seen here:

(4*8^4) + (1*8^3) + (6*^8^2) + (5*8^1) + no digits left to multiply 8^0 by

So, in order to fix this issue, a 0 is added to the beginning of the octal number, making it 04165. Now the equation looks like this:

(0*8^4) + (4*8^3) + (1*8^2) + (6*8^1) + (5*8^0)

.     0   +    2048   +    64     +     48     +     5    =    2165

8^^4165 unsigned = 10^^2165

In order to convert the octal numbers into decimal, assuming they are stored in sign-magnitude format, the numbers should be converted first to binary, in order to check the most significant bit (MSB) to see whether the numbers are positive or negative. If the MSB in a binary number stored in sign-magnitude format is a 0, the number is positive. If the MSB is a 1, the number is negative. The MSB in sign-magnitude numbers is no longer a countable, operable part of the number, it is essentially a +/- sign. Since these numbers have all so far been in 12-bit format, if they are in sign-magnitude format, values can only be displayed using the rightmost (or least significant) 11 bits. The 12th, or most significant bit, is reserved for the 0 or 1 that represents the + or – sign.

a. 3174

When converted to binary, 3174 becomes 011 001 111 100. The most significant bit here is a 0, meaning the number is positive. When the MSB is excluded from the number itself, the first digit remains the same in this case, 011 becomes 11, which is still 3. So, the number remains the same, positive 3174. To convert it to decimal, the same method shown above for unsigned numbers is used.

(3*8^3) + (1*8^2) + (7*8^1) + (4*8^0)

1536       +      64       +      56       +       4     =      1660

8^^3174 sign-magnitude = 10^^1660

b. 4165

The same is done for part b for the octal number 4165. When converted to binary, it becomes 100 001 110 101. In this case, the MSB is a 1, meaning the number is negative. Excluding the sign bit from the number, 11 bits are left with which to represent the rest of the number. Notice that the rest of the bits used to represent the leftmost digit in 4165 are now 00. This means that the number is now -0165.

(1*8^2) + (6*8^1) + (5*8^0)

.   64      +      48       +       5        =    117

And when the sign bit is included, it is -117.

8^^4165 sign-magnitude = 10^^-117

3.1.4 What is A – B if they represent unsigned 12-bit octal numbers? The result should be written in octal.

.        A              B

a.  7040          0444

b.    4365         3412

a.     7040

–      0444

————-

.       6374

Subtraction between octal numbers can be done by hand from right to left, just like addition, using the same concepts as decimal subtraction. In this case, the octal number 0444 is being subtracted from the octal number 7040. Starting at the right (the ones column), the first operation to be performed is 0 – 4. Since 4 cannot be subtracted from 0 in this manner, a value must be borrowed from the tens column (or eights column, in the case of base 8) and added to the 0 in the ones column so that the operation can be performed. In base 8, the value that is borrowed is 8, just as it is 10 in base 10. So, 1 is subtracted from the 4 in the eights column, allowing 8 to be added to the 0 in the ones column. So, at this point, the operation is 7038 – 0444.

After subtracting 4 from 8 and placing 4 in the ones place, the eights column is addressed. Since the original 4 in 7040’s eights place was borrowed from, it is now 3, which cannot be subtracted from the 4 in 0444’s eights place, so another borrow must be done, this time from the hundreds place (or 64s place in base 8). However, since the 64s column in 7038 contains a 0, the 512s column mu be borrowed from. The borrowed 8 from the 512s column is then placed in the 64s column. The 3 in the eights column can then borrow from the 64s column, making it 11, which is then subtracted from 4, resulting in a 7 being placed in the eights place.

Now, the last 4 in 0444’s 64s place is subtracted from the remaining 7 in the 64s place, resulting in a 3 being placed in the 64s place. Finally, the operation between the last two digits, 6 and 0 in the 512s place, makes the first digit of the answer 6. So, now, we have the difference of 8^^7040 – 8^^0444 = 8^^6374.

b.    4365

–      3412

————-

.       0753

Part b requires quite a bit less work than part a. Using the same method as shown in part a, first the digits in the ones column are subtracted. in this case, 2 is subtracted from 5, resulting in 3 being stored in the ones place. Next, in the eights column, 1 is subtracted from 6, resulting in 5 being placed in the eights column. Then, in the 64s column, 4 is being subtracted from 3, so an 8 must be borrowed from the 4 in the 512s column of 4365. The resulting 11 (8+3=11) is then subtracted from 4 and a 7 is placed in the 64s place. Finally, the leading 3 in 3412 is subtracted from the remaining 3 in the leftmost bit of 4365 after the carry, resulting in 0. So, the difference of 8^^4365 – 8^^3412 = 8^^0753.

3.1.5 What is A – B if they represent signed 12-bit octal numbers stored in sign-magnitude format? The result should be written in octal.

a. If the numbers are signed 12-bit octal numbers stored in sign-magnitude format, they should be converted into binary in order to determine the whether they are positive or negative by checking the MSB (sign bit in sign-magnitude format).

Starting with 8^^7040 = 2^^111 000 100 000

In this case, since the leading digit is a 7, the MSB is a 1, which means that the number is negative. Excluding the sign bit, the number is now (0)11 000 100 000, or 8^^-3040.

Doing the same for 8^^0444 = 2^^000 100 100 100

Here, the MSB is a 0, meaning that the number is positive. Excluding the sign bit, the number remains the same; (0)00 100 100 100, or 8^^0444

-3040

-0444

—————-

-3504

Since subtracting a positive number from a negative number is basically the same as addition, the result of this equation is acquired through the same method as addition, not subtraction. Values are carried, not borrowed. First, 0 and 4 are added, summing to 4 in the ones place. Next, the two 4’s in the eights column are added, resulting in 8, so a 0 is placed in the eights place and a 1 is carried over to the 0 in -3040’s 64s column. That 1 is then added to 4, giving the 64s place a 5 digit. Finally, 3 and 0 are added, and the resulting 3 is placed in the 512s place. The result is 8^^-3040 – 8^^0444 = 8^^-3504.

On a side note, I’ve noticed that, in sign-magnitude format, if the leftmost octal digit is 0, 1, 2, or 3, the number is positive. However, if the leftmost octal digit is 4, the value in sign-magnitude becomes -0. If the digit is a 5, it becomes -1. If it is 6, it becomes -2, or if it is 7, it becomes -3.

b. First, the octal numbers are converted to binary. 8^^4365 = 2^^100 011 110 101, 8^^3412 = 2^^011 100 001 010

Due to the leftmost bit in 4365 being a 4, the leftmost bit in its binary conversion (100 011 110 101) is a 1. This means that the number is negative. After excluding the sign bit, the number becomes (0)00 011 110 101, or 8^^0365. Including the sign makes it 8^^-0365. Just as in part a, the second octal number here, 3412, is positive and remains the same. The MSB is a 0, making the number positive. The remaining digits are then (0)11 100 001 010, or 8^^3412.

-0365

-3412

———

-3777

The same operation as performed in part a is performed here. The numbers are added, since the signs are the same (negative sign in -0365 and subtraction sign next to 3412) starting with the  5 and 2 in the ones column, giving a 7 to the ones place. Then, the 6 and 1 in the eights column are added together and the resulting 7 is placed in the eights place. Next, the 3 and 4 in the 64s column are added, again summing to 7, which is stored in the 64s place. Finally, the leftmost digits, 0 and 3, are added and the resulting 3 is stored in the 512s place. Thus, the difference of 8^^-0365 – 8^^3412 = 8^^-3777.

3.1.6 Convert A into a binary number. What makes base 8 (octal) an attractive numbering system for representing values in computers?

Converting octal numbers into binary numbers is a fairly straightforward process. Simply replace each digit in the octal number with the binary counterpart of the digit. For example, using 7040:

a. 8^^ 7 0 4 0 = 2^^111 000 100 000

The binary representation of 7 is 111, 0 would be 000, 4 is 100, and again, 0 is 000. Putting this together, you get 8^^7040 = 2^^111000100000.

b. 8^^4 3 6 5 = 100 011 110 101

The binary representation of 4 is 100, 3 is 011, 6 is 110, and 5 is 101. Putting these numbers together gives 8^^4365 = 2^^100011110101.

The reason that base 8 (octal) is an attractive numbering system for representing values in computers is the fact that 8 = 2^3, meaning that each octal digit displays exactly 3 binary digits, thus making base 8 a very efficient shorthand for base 2.

I’ve checked all of my math and conversions for accuracy using http://www.wolframalpha.com.

3.2 The following table shows pairs of hexadecimal numbers.

.            A            B

a.    1446        672F

b.   2460       4935

3.2.1 What is the sum of A and B if they represent unsigned 16-bit hexadecimal numbers? The result should be in hexadecimal.

Hexadecimal is another well-known numbering system that stands alongside octal and decimal. Just as octal is a base 8 number system consisting of the digits 0, 1, 2,  3, 4, 5, 6, and 7 and decimal is a base 10 system consisting of the digits 0 – 9, hexadecimal is a base 16 number system using the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F, where A represents 10, B is 11, C = 12, D is 13, E is 14, and F is 15. Despite looking quite different from other number systems, such as base 8 and base 10, due to have letters instead of just numbers, the same concepts that apply in other number systems still apply in base 16.

For example, addition in hexadecimal works the same way as it would in other number systems. Here, F (or 15) is the highest digit, the same way 9 is the highest digit in decimal and 7 is the highest digit in octal.

a.  1446

+   672F

———–

.     7B75

In this equation, the first operation performed is the addition of the two rightmost digits, 6 and F. Remember that F represents 15, so 6 + F = 21. Since F is the greatest digit that can be represented in base 16, and 21 > F, 21 must be carried to the next column, just as a number greater than 7 would be in base 8 or a number greater than 9 would be in base 10. So, the difference of 21 and 16, which is 5, is placed in the ones place and a 1 is carried over to the tens column (or 16s column in the case of base 16). Next, the carried 1 is added to the 4 and 2 in the 16s column and the resulting 7 (1+4+2=7) is placed in the 16s place. Then, the digits in the 256s column, 4 and 7, are added, which gives 11. Since the value of 11 is represented by the digit B, there is no need to carry here, as there would’ve been in base 8 or 10. Finally, the two rightmost digits, 1 and 6, are added and the resulting 7 is stored in the 4096s place. Thus, the final sum of 16^^1446 + 16^^672F = 16^^7B75.

b.  2460

+   4935

————

.     6D95

Part b is solved the same way. There are not even any carries this time. First, 0 and 5 are added, and 5 is put in the ones place. Next, 6 and 3 are added, with the sum being stored in the 16s place. Then, moving to the 256s column, 4+9=13. Since 13 = D in base 16, there is no need to carry, so D is placed in the 256s place. Finally, 2+4 results in a 6 in the 4096s place.

3.2.2 What is the sum of A and B if they represent signed 16-bit hexadecimal numbers stored in sign-magnitude format? The result should be written in hexadecimal. 

a. If A and B represent signed 16-bit hexadecimal  numbers stored in sign-magnitude format, in order to operate with them, their signs must first be determined.

Some useful observations I’ve made:

16^^1446

(1*16^3) + (4*16^2) + (4*16^1) + (6*16^0)

4096     +       1024   +      64       +     6       =       10^^5190     =      2^^0001 0100 0100 0110

16^^672F

(6*16^3) + (7*16^2) + (2*16^1) + (15*16^0)

24576    +      1792       +        32        +        15      =      10^^26415   =     2^^0110 0111 0010 1111

Base 16 numbers can also be converted directly to base 2 without converting to base 10 in the process, the same way base 8 is converted to base 2. The only difference is that base 16 digits display 4 base 2 digits, where base 8 displayed 3. For example:

16^^1 4 4 6 = 2^^0001 0100 0100 0110

The last 4 bits in the binary number represent the last digit in the hexadecimal number, in this case, 6. The second to last group of 4 bits in the binary number represent the second to last digit in the hexadecimal number, which is 4 here. The second leftmost group of 4 bits in the binary number represent the second leftmost digit in the hexadecimal number, which is also 4. Finally, the leftmost group of 4 bits represents the leftmost digit in the hexadecimal number, which is 1 here.

Also, just as with signed base 8 numbers with leftmost digits 4, 5, 6, and 7 becoming -0, -1, -2, and -3, a similar rule seems to apply to base 16 numbers. Looking at the 4 most significant bits in the base 2 conversions shown above, you will notice that the MSB would be a 1 if the leftmost digit in the base 16 number was an 8, making the 4 most significant digits 1000, or -0 in sign magnitude format. Similarly, if the leftmost base 16 digit was a 9, the 4 leftmost digits digits in the binary number would be 1001, or -1 in sign-magnitude format. Continuing with this pattern, A would be -2, B would be -3, C would be -4, D would be -5, E would be -6, and F would be -7.

Moving on to the problem. Using the information stated above, it is apparent that the base 16 numbers 1446 and 672F are both positive if stored in sign-magnitude format because the most significant digit is less than 8 in both cases. This is further proven by the fact that neither number has a 1 as its most significant bit when converted to base 2. 16^^1446 = 2^^0001 0100 0100 0110, 16^^672F = 2^^0110 0111 0010 1111

.     1446

+    672F

————

.      7B75

Thus, the operation and result remain the same as the unsigned version in this case. Again, 6 and F are added first, the sum is 21, so 1 is carried to the next column and 5 is stored in the ones place. Then, the carried 1 is added to 4 and 2, and 7 is stored in the 16s place. Next, 4 and 7 are added, and the resulting 11 is represented in the 256s place as B. Finally, the leftmost 1 and 6 are added, with the resulting 7 being placed in the 4096s place, giving the final sum of 16^^7B75.

b. The same methods used in part a are used to solve part b. 2460 and 4935 are the two base 16, 16-bit numbers stored in sign-magnitude format to be added. Notice that, once again, neither number has a most significant digit of 8 or greater. This means that both numbers are positive and can be added just as they were earlier.

.       2460

+     4935

————-

.       6D95

Just as they were added in the unsigned problem, the 0 and 5 are first added and 5 is placed in the ones column. Next, the 6 and 3 are added, resulting in 9 in the 16s column. 4 and 9 are then added, summing to 13, which is represented by D in the 256s place. Finally, 2+4=6 in the 4096s place.

3.2.3 Convert A into a decimal number, assuming it is unsigned. Repeat assuming it stored in sign-magnitude format.

In order to convert a base 16 number into base 10, each digit in the base 16 number is multiplied by a corresponding power of 16, in descending order. So, for 16^^1446, 1 is multiplied by 16^3, the leftmost 4 is multiplied by 16^2, the second 4 is multiplied by 16^1, and 6 is multiplied by 16^0. All of the quantities are then added together. The sum is the base 10 representation of 16^1446.

a. 16^^1446

(1*16^3) + (4*16^2) + (4*16^1) + (6*16^0)

4096       +       1024     +       64        +      6      =      5190

16^^1446 = 10^^5190

b. 16^^2460

(2*16^3) + (4*16^2) + (6*16^1) + (0*16^0)

8192         +    1024       +      96         +        0         =      9312

16^^2460 = 10^^9312

Due to the fact that 16^^1446 and 16^^2460 both have most significant digits below 8, they would both be positive numbers if stored in sign-magnitude format. Thus, their values remain the same.

a. 16^^1446 sign-magnitude

(1*16^3) + (4*16^2) + (4*16^1) + (6*16^0)

4096       +       1024     +       64        +      6      =      5190

16^^1446 sign-magnitude = 10^^5190

b. 16^^2460 sign-magnitude

(2*16^3) + (4*16^2) + (6*16^1) + (0*16^0)

8192         +    1024       +      96         +        0         =      9312

16^^2460 sign-magnitude = 10^^9312

3.2.4 The following table also shows pairs of hexadecimal numbers.

.            A           B

a.    C352     36AE

b.   5ED4      07A4

What is A – B if they represent unsigned 16-bit hexadecimal numbers? The result should be written in hexadecimal.

a.         C352

–           36AE

—————-

.            8CA4

Since the numbers are unsigned here, they are simply subtracted. Starting from the right, since E cannot be subtracted from 2, a 16 is borrowed from the 5 in the next column. the resulting 18 is then subtracted from E, leaving 4 in the ones place. Next, since A cannot be subtracted from 4 (since it was borrowed from, 5-1=4), another 16 is borrowed from the next column. The result is 20, from which A is subtracted, leaving A in the 16s place. Then, since 6 cannot be subtracted from 2 (since 3 was borrowed from, 3-1=2), yet another borrow must be done from the next column, reducing C in the 4096s column to B and increasing 2 to 18. 6 is then subtracted from 18, resulting in C being stored in the 256s place. Finally, 3 is subtracted from the remaining B, leaving 8 in the 4096s place. So, 16^^C352 – 16^^36AE = 16^^8CA4.

b.        5ED4

–          07A4

—————

.            5730

Part b follows the same steps, but requires quite a bit less work. There are no carries involved. To begin with, 4 is subtracted from 4, leaving 0 in the ones place. Next, A is subtracted from D, resulting in a 3 in the 16s place. Then, 7 is subtracted from E, leaving 7 in the 256s place. Finally, 0 is subtracted from 5, so the leftmost digit is 5. 16^^5ED4 – 16^^07A4 = 16^^5730.

3.2.5 What is A – B if they represent signed 16-bit hexadecimal numbers stored in sign-magnitude format? The result should be written in hexadecimal.

a. Since the numbers are signed and stored in sign-magnitude format, the value of C352 changes, due to the fact that its leftmost digit is C >= 8. For hexadecimal numbers stored in sign-magnitude format with a leftmost digit of 8 or greater, the value becomes negative because leftmost digits 8 and greater have a MSB of 1 when converted to base 2. In this format, a hexadecimal number with a 0, 1, 2, 3, 4, 5, 6, or 7 as the most significant digit remains the same, while a hexadecimal number with a most significant digit of 8 becomes -0 (16^^8 = 2^^1000, 1 becomes the negative sign bit and the remaining 3 bits represent the number, which is now 0 in this case). Following this pattern, a 9 as the most significant digit in a base 16 number becomes -1 in sign-magnitude format (16^^9 = 2^^1001, the leftmost 1 is again used to represent the negative sign bit, while the remaining 3 bits represent the number, which becomes 1). So, A as the most significant hexadecimal digit in sign magnitude format becomes -2, B becomes -3, C becomes -4, D becomes -5, E becomes -6, and F becomes -7.

With this in mind, it is apparent that the first hexadecimal number in part a, C352, becomes -4352 in sign-magnitude format, since C >=8. 16^^C = 2^^1100.Since the MSB is reserved for the sign bit, which is negative, the remaining 3 bits, 100, are used to represent the leftmost digit, which then becomes 4. The second hexadecimal number in the problem, 36AE, however, remains the same due to its leftmost digit being below 8. The leftmost digit is 3, and 16^^3 = 2^^0011. So, theMSB indicates that the number is positive, and since the number 3 only requires the two rightmost bits to be represented, it remains unchanged if its leftmost bit is reserved for the sign bit.

.      -4352

–       36AE

————–

.       -7A00

Since a positive number is being subtracted from a negative number, addition is performed and the negative sign is kept. 2+E=16, so a 0 is put in the ones place and a 1 is carried. 1+5+A=16 again, so a 0 is put in the 16s place and a 1 is carried again. 1+3+6=A, so A ends up in the 256s place. Finally, 4+3=7 in the 4096s place.

b. By looking at the leftmost digits of both numbers in part b, it is apparent that the problem will be much less eventful than part a. The leading digits of both are a 5 and a 0, so when in sign-magnitude format, the values remain the same.

.        5ED4

–       07A4

————–

.        5730

No negative numbers, no value conversions, no borrows, nothing. Just basic subtraction of two positive numbers, the same operation presented in part b of the unsigned problem. First, 4 is subtracted from 4, leaving 0 in the ones place. Next, A is subtracted from D, and the resulting 3 is stored in the 16s place. Then, 7 is subtracted from E, leaving 7 in the 256s place. Finally, 0 is subtracted from 5, so 5 is placed in the 4096s place.

3.2.6 Convert A into a binary number.What makes base 16 (hexadecimal) an attractive numbering system for representing values in computers?

To convert base 16 numbers to base 2, simply use 4 bits to represent each digit in the base 16 number.

a. C352, C (or 12) represented in binary is 1100, 3 is 0011, 5 is 0101,  and 2 is 0010.

16^^C 3 5 2 = 2^^1100 0011 0101 0010

b. 5ED4, 5 represented in binary is 0101, E (or 14) is 1110, D (or 13) is 1101, and 4 is 0100

16^^5 E D 4 = 2^^0101 1110 1101 0100

Base 16 is an attractive numbering system for representing values in computers because 16 = 2^4, so each digit in a hexadecimal number displays 4 bits. Due to this, a byte (8 bits) can be specified by exactly 2 hexadecimal digits.

I’ve checked all of my math and conversions for accuracy using http://www.wolframalpha.com.

Leave a comment