Skip navigation

Tag Archives: binary

This solution is for the book I am currently reading. All of my notes and solutions are available at Google Code.

Here is my work for problem 2.24:

Suppose we truncate a 4-bit value (represented by hex digits 0 through F) to a 3-bit
value (represented as hex digits 0 through 7). Fill in the table below showing
the efffect of this truncation for some cases, in terms of the unsigned and two's
complement interpretations of those bit patterns.

        Hex                   Unsigned           Two's complment
---------------------- ----------------------- -------------------
Original    Truncated   Original    Truncated   Original Truncated
------------------------------------------------------------------
   0            0          0            0          0         0
------------------------------------------------------------------
   2            2          2            2          2         2
------------------------------------------------------------------
   9            1          9            1         -7         1
------------------------------------------------------------------
   B            3         11            3         -5         3
------------------------------------------------------------------
   F            7         15            7         -1        -1
------------------------------------------------------------------

WorK:


2U
0010
 010 = 2

2
0010
 010 = 2

9U
1001
 001 = 1
9 mod 8 = 1

-7 = -8 + 1
1001
 001 = 1
-7 mod 8 = 1
U2T(1) = 1

11U
1011
 011 = 3
11 mod 8 = 3

-5 = -8 + 4 + 1
1011
 011 = 3
-5 mod 8 = 3
U2T(3) = 3

15U
1111
 111 = 4 + 2 + 1 = 7
15 mod 8 = 7

-1 = -8 + 4 + 2 + 1
1111
 111 = -4 + 2 + 1 = -1
-1 mod 8 = 7
U2T(7) = -1

Advertisements

This solution is for the book I am currently reading. All of my notes and solutions are available at Google Code.

Here is my work for problem 2.22:

Show that each of the following bit vectors is a two's complement representation
of -5 by applying Equation 2.3

A. [1011]
B. [11011]
C. [111011]

Observe that the second and third bit vectors can be derived from the first by sign
extension.

Answers:

A.
 1011
 -(1 * 2^3) + (0 * 2^2) + (1 * 2^1) + (1 * 2^0)
 -8 + 0 + 2 + 1
 -8 + 3
 -5

B.
 11011
 -(1 * 2^4) + (1 * 2^3) + (0 * 2^2) + (1 * 2^1) + (1 * 2^0)
 -16 + 8 + 0 + 2 + 1
 -8 + 3
 -5

c.
 111011
 -(1 * 2^5) + (1 * 2^4) + (1 * 2^3) + (0 * 2^2) + (1 * 2^1) + (1 * 2^0)
 -32 + 16 + 8 + 0 + 2 + 1
 -16 + 8 + 3
 -8 + 3
 -5



This solution is for the book I am currently reading. All of my notes and solutions are available at Google Code.

Here is my work for problem 2.19:

Explain how Equation 2.4 applies to the entires in the table
you generated when solving Problem 2.18

You simply add 2^w where w = number of bits to convert to
the two's complement value to convert to unsigned if two's
complement of x is a negative value (most signficant
bit is flipped).


  x   T2U₄(x)
 -------------
 -8     8       1000    2^3        = 2^4 + -2^3
                          8        = 16 - 8

 -------------
 -6    10       1010    2^3 + 2^1  = x + -2^3 + 2^1
                           10      = x + -6
                           16      = x
                           2^4 = 2 * 2 * 2 * 2 = 16

 -------------
 -4    12       1100     2^3 + 2^2 =  2^4 + -2^3 + 2^2
                          8  +  4  =  16 +   -8  + 4
                            12     =  16 + -4 =

 -------------
 -1    15       1111   2^3 + 2^2 + 2^1 + 2^0 = 2^4 + -2^3 + 2^2 + 2^1 + 2^0
                        8  +  4  +  2  +  1  =  16 +  -8  +  4  +  2  +  1
                          12     +     3     =     8      +       7
                                 15          =         15
 -------------
  0     0
 -------------
  3     4
 -------------




This solution is for the book I am currently reading. All of my notes and solutions are available at Google Code.

Here is my work for problem 2.18:

Using the table you filled in when solving Problem 2.16, fill in the
following table describing the function T2U₄:


  x   T2U₄(x)
 -------------
 -8
 -------------
 -6
 -------------
 -4
 -------------
 -1
 -------------
  0
 -------------
  3
 -------------


(from 2.16):

  Hexadecimal  Binary                    Unsigned         Signed
  -------------------------------------------------------------------------------
       A        1010               2^3 + 2^1 = 10                 -2^3 + 2^1 = -6
  -------------------------------------------------------------------------------
       0        0000                       0 =  0                          0 =  0
  -------------------------------------------------------------------------------
       3        0011               2^2 + 2^0 =  3                  2^2 + 2^0 =  3
  -------------------------------------------------------------------------------
       8        1000                     2^3 =  8                       -2^3 = -8
  -------------------------------------------------------------------------------
       C        1100               2^3 + 2^2 = 12                 -2^3 + 2^2 = -4
  -------------------------------------------------------------------------------
       F        1111   2^3 + 2^2 + 2^1 + 2^0 = 15    -2^3 + 2^2 + 2^1 + 2^0 =  -1
  -------------------------------------------------------------------------------


  x   T2U₄(x)
 -------------
 -8     8
 -------------
 -6    10 
 -------------
 -4    12 
 -------------
 -1    15 
 -------------
  0     0 
 -------------
  3     4
 -------------



This solution is for the book I am currently reading. All of my notes and solutions are available at Google Code.

Here is my work for problem 2.17: – this one was a lot of work :( – still fun to get it right though :P

For the lines labeled A-K in the following listing, convert the
hexadecimal values (two's complement) shown to the right of the instruction names
(not shown here, check your book, too much too type!) into their
decimal equivalents.

A. 0x184
B. 0x8
C. 0xc
D. 0x10
E. 0xfffffe94
F. 0x10
G. 0xfffffea0
H. 0xffffff10
I. 0x1c
J. 0xffffff7c
K. 0x18

A. 0x184

     1    8    4
  0001 1000 0100
  1098 7654 3210

     2^8 + 2^7 + 2^2 = 388

B. 0x8

   0x8 is 0x08 (hex binary values must have two digits to get 8 bits)

     0     8
  0000  1000 = 8


C. 0xc

   0xc = 0x0c (hex binary values must have two digits to get 8 bits)

     0    c
  0000 1100 =
       3210
       2^3 + 2^2 = 12

D. 0x10

     1    0
  0001 0000 = 2^4 = 16

E. 0xfffffe94

     f    f    f    f    f    e    9    4
  1111 1111 1111 1111 1111 1110 1001 0100
          0         0 5432 1098 7654 3210
  -2^15 + 2^14 + 2^13 + 2^12 +  2^11 + 2^10 + 2^9 + 2^7 + 2^4 + 2^3 = -364


F. 0x10

     1    0
  0001 0000 = 16

G. 0xfffffea0

     f    f    f    f    f    e    a    0
  1111 1111 1111 1111 1111 1110 1010 0000
          0         0 5432 1098 7654 3210
  -2^15 + 2^14 + 2^13 + 2^12 +  2^11 + 2^10 + 2^9 + 2^7 + 2^5 = -352

H. 0xffffff10

     f    f    f    f    f    f    1    0
  1111 1111 1111 1111 1111 1111 0001 0000
          0         0 5432 1098 7654 3210
   -2^15 + 2^14 + 2^13 + 2^12 +  2^11 + 2^10 + 2^9 + 2^8 + 2^4 = -240

I. 0x1c

     1    c
  0001 1100
     16 + 8 + 4 = 28

J. 0xffffff7c

     f    f    f    f    f    f    7    c
  1111 1111 1111 1111 1111 1111 0111 1100
          0         0 5432 1098 7654 3210
  -2^15 + 2^14 + 2^13 + 2^12 +  2^11 + 2^10 + 2^9 + 2^8 + 2^6 + 2^5 + 2^4 + 2^3 + 2^2 = -132

K. 0x18

     1    8
  0001 1000
     16 + 8 = 24

This solution is for the book I am currently reading. All of my notes and solutions are available at Google Code.

Here is my work for problem 2.16:

Assuming w = 4, we can assign a numeric value to each possible hexadecimal
digit, assuming either an unsigned or two's-complement interpretation. Fill in
the following table according to these interpretations by writing out the nonzero
powers of two in the summations shown in Equation 2.1 and 2.2 (in the book pg 52).



  Hexadecimal  Binary     Unsigned         Signed
  -----------------------------------------------------
       A        1010   2^3 + 2^1 = 10  -2^3 + 2^1 = -6
  -----------------------------------------------------
       0
  -----------------------------------------------------
       3
  -----------------------------------------------------
       8
  -----------------------------------------------------
       C
  -----------------------------------------------------
       F
  -----------------------------------------------------


Answers:

  Hexadecimal  Binary                    Unsigned         Signed
  -------------------------------------------------------------------------------
       A        1010               2^3 + 2^1 = 10                 -2^3 + 2^1 = -6
  -------------------------------------------------------------------------------
       0        0000                       0 =  0                          0 =  0
  -------------------------------------------------------------------------------
       3        0011               2^2 + 2^0 =  3                  2^2 + 2^0 =  3
  -------------------------------------------------------------------------------
       8        1000                     2^3 =  8                       -2^3 = -8
  -------------------------------------------------------------------------------
       C        1100               2^3 + 2^2 = 12                 -2^3 + 2^2 = -4
  -------------------------------------------------------------------------------
       F        1111   2^3 + 2^2 + 2^1 + 2^0 = 15    -2^3 + 2^2 + 2^1 + 2^0 =  -1
  -------------------------------------------------------------------------------


This solution is for the book I am currently reading. All of my notes and solutions are available at Google Code.

Here is my work for problem 2.15:

Fill in the table below showing the effects of the different shift operations
on single-byte quantities. The best way to think about shift oeprations
is to work with binary representations. Convert the initial values to binary, 
perform shifts, and then convert back to hexadecimal. Each of the answers 
should be 8 binary digits or 2 hexadecimal digits.



-------------------------------------------------------------------------
       x                x << 2           x >> 2
                                        (Logical)       (Arithmetic)
-------------------------------------------------------------------------
  Hex     Binary    Hex     Binary    Hex     Binary    Hex     Binary
-------------------------------------------------------------------------
  0xF0
-------------------------------------------------------------------------
  0x0F
-------------------------------------------------------------------------
  0xCC
-------------------------------------------------------------------------
  0x55
-------------------------------------------------------------------------


0xF0

  0xF0
  11110000

  x << 2 (Logical)

  0x3C
  00111100

  x >> 2 (Arithmetic)

  0xFC
  11111100

0x0F

  0x0F
  00001111

  x << 2 (Logical)

  0x03
  00000011

  x >> 2 (Arithmetic)

  0x03
  00000011


0xCC

  0xCC
  11001100

  x << 2 (Logical)

  0x33
  00110011

  x >> 2 (Arithmetic)

  0xF3
  11110011

0x55

  0x55
  01010101

  x << 2 (Logical)

  0x15
  00010101

  x >> 2 (Arithmetic)

  0x15
  00010101

-------------------------------------------------------------------------
       x                x << 2           x >> 2
                                        (Logical)       (Arithmetic)
-------------------------------------------------------------------------
  Hex     Binary    Hex     Binary    Hex     Binary    Hex     Binary
-------------------------------------------------------------------------
  0xF0   11110000  0x80    10000000  0x3C    00111100  0xFC   11111100
-------------------------------------------------------------------------
  0x0F   00001111  0x78    01111000  0x03    00000011  0x03   00000011
-------------------------------------------------------------------------
  0xCC   11001100  0x60    01100000  0x33    00110011  0xF3   11110011
-------------------------------------------------------------------------
  0x55   01010101  0xA8    10101000  0x15    00010101  0x15   00010101
-------------------------------------------------------------------------


This solution is for the book I am currently reading. All of my notes and solutions are available at Google Code.

Here is my work for problem 2.9:

We can create eight different colors based on the absence (0) or presence
(1) of light sources R, G, and B:

  R  G  B  Color
 ------------------
  0  0  0  Black
 ------------------
  0  0  1  Blue
 ------------------
  0  1  0  Green
 ------------------
  0  1  1  Cyan
 ------------------
  1  0  0  Red
 ------------------
  1  0  1  Magenta
 ------------------
  1  1  0  Yellow
 ------------------
  1  1  1  White
 ------------------

This set of colors forms an eight-element Boolean algebra.

A. The complement of a color is formed by turning off the lights that are on
and turning on the lights that are off. What would be the complements of
the eight colors listed above?

B. What colors correspond to Boolean values 0^w and 1^w for this algebra?

C Describe the effect of applying Boolean operations on the following colors:

      Blue | Red   =
   Magenta & Cyan  =
     Green ^ White =

A.

  R  G  B  Color       R  G  B  Complement
 -----------------------------------------
  0  0  0  Black    =  1  1  1   White
 ------------------------------------------
  0  0  1  Blue     =  1  1  0   Yellow
 ------------------------------------------
  0  1  0  Green    =  1  0  1   Magenta
 ------------------------------------------
  0  1  1  Cyan     =  1  0  0   Red
 ------------------------------------------
  1  0  0  Red      =  0  1  1   Cyan
 ------------------------------------------
  1  0  1  Magenta  =  0  1  0   Green
 ------------------------------------------
  1  1  0  Yellow   =  0  0  1   Blue
 ------------------------------------------
  1  1  1  White    =  0  0  0   Black
 ------------------------------------------


B.

  0^w is Black
  1^w is White

C.

  Blue  |  Red =   0 0 1
                   1 0 0
                   -----
                   1 0 1  = Magenta

  Magenta & Cyan = 1 0 1
                   0 1 1
                   -----
                   0 0 1  = Blue

  Green ^ White  = 0 1 0
                   1 1 1
                   -----
                   1 0 1  = Magenta


This solution is for the book I am currently reading. All of my notes and solutions are available at Google Code.

Here is my work for problem 2.4:

Without converting the numbers to decimal or binary, try to solve the following
arithmetic problems, giving the answers in hexadecimal. Hint: just modify
the mothods you use for performing decimal addition and subtraction to use
base 16.

A. 0x502c + 0x8 =
B. 0x502c - 0x30 =
C. 0x502c + 64 =
D. 0x50da - 0x502c =

A. 0x502c + 0x8 =

  0x502c
  +  0x8
  ------
  0x5034

B. 0x502c - 0x30 =

  0x502c
  - 0x30
  ------
  0x4ffc


C. 0x502c + 64 =

  64 = 4 * 16 + 0
  4 = 0 * 16 + 4
  64 = 0x40

  0x502c
  + 0x40
  ------
  0x506c


D. 0x50da - 0x502c =

  0x50da
 -0x502c
 -------
    0xae

A. 0x502c + 0x8 = 0x5034
B. 0x502c - 0x30 = 0x4ffc
C. 0x502c + 64 = 0x506c
D. 0x50da - 0x502c = 0xae


This solution is for the book I am currently reading. All of my notes and solutions are available at Google Code.

Here is my work for problem 2.3:

A single byte can be represented by two hexadecimal digits. Fill in the missing 
entries in the following table, giving the decimal, binary and hexadecimal 
values of different byte patterns.

-------------------------------
Decimal   Binary    Hexadecimal
-------------------------------
    0    00000000       00
-------------------------------
   55
-------------------------------
  136
-------------------------------
  243
-------------------------------
         01010010
-------------------------------
         10101100
-------------------------------
         11100111
-------------------------------
                        A7
-------------------------------
                        3E
-------------------------------
                        BC
-------------------------------


1)
Decimal = 55
  55/16 = 3
  16 * 3 = 48
  56 - 48 = 7
 A) 55 = 3 * 16 + 7 (7)
  3/16 = 0
 B) 3 = 0 * 16 + 3 (D)
 Hexadecimal = 0x37
 Binary = 00010111

2)
Decimal = 136
    8 * 16 = 128
    136 - 128 = 8
  A) 136 = 8 * 16 + 8
    8/16 = 0
  B) 8 = 0 * 16 + 8
  Hexadecimal = 0x88
  Binary = 10001000


3)
Decimal = 243
    16 * 15 = 240
    243 - 240 = 3
  A) 243 = 15 * 16 + 3
  B) 15 = 0 * 16 + 15
  Hexadecimal = 0xF3
  Binary = 11110011

4)
Binary = 01010010
  Hexadecimal = 0x52
    = 5 * 16 + 2
    = 50 + 30 + 2
  Decimal = 82

5)
Binary = 10101100
  Hexadecimal = 0xAC
      = 10 * 16 + 12
      = 160 + 12
  Decimal = 172

6)
Binary = 11100111
  Hexadecimal = 0xE7
      = 14 * 16 + 7
      = 224 + 7
  Decimal = 231

7)
Hexadecimal = A7
  Binary = 10100111
      = 128+32+4+2+1
  Decimal = 167

8)
Hexadecimal = 3E
  Binary = 00111110
      = 2 + 4 + 8 + 16 + 32
  Decimal = 62

9)
Hexadecimal = BC
  Binary = 10111100
      = 4 + 8 + 16 + 32 + 128
  Decimal = 188

-------------------------------
Decimal    Binary    Hexadecimal
-------------------------------
    0    0000 0000       00
-------------------------------
   55    0001 0777       37
-------------------------------
  136    1000 1000       88
-------------------------------
  243    1111 0011       F3
-------------------------------
   82    0101 0010       52
-------------------------------
  172    1010 1100       AC
-------------------------------
  231    1110 0111       E7
-------------------------------
  167    1010 0111       A7
-------------------------------
   62    0011 1110       3E
-------------------------------
  188    1011 1100       BC
-------------------------------