Skip navigation

Tag Archives: conversion

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.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
-------------------------------


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

To convert decimal value x to hexadecimal, we repeatedly devide by 16
giving a quotent q and a reamainder r such that x = q * 16 + 4
r becomes the *least* signficant digit for the hexadecimal value

As an example: x = 314156

  314145 = 19634 * 16 + 12 (C)
   19634 = 1227 * 16 + 2   (2)
    1227 = 76 * 16 + 11    (B)
      76 = 4 * 16 + 12     (C)
       4 = 0 * 16 + 4      (4)

314156 in hexadecimal is 0x4CB2C

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.2:

Problem

Fill in the blank entries in the following table, given the decimal and
hexadecimal representation of different powers of 2:


n     2^n (Decimal)       2^n (Hexadecimal)
--------------------------------------------
11        2048                 0x800
--------------------------------------------
 7
--------------------------------------------
          8192
--------------------------------------------
                             0x20000
--------------------------------------------
16
--------------------------------------------
           256
--------------------------------------------
                                0x20
--------------------------------------------

1)
  n = 7
  2^7 = Decimal form: 128
  7 = i + 4j where 0 <= i <= 3
    7 = 3 + 4 ( 1 )
    i = 3, j = 1
    Hexadecimal form: 0x80

2)
  Decimal value = 8192
  8192 log2 = n = 13
  13 = i + 4j where 0 <= i <= 3
    13 = 1 + 4 ( 3 )
    13 = 1 + 12
    i = 1, j = 3
    Hexadecimal form: 0x2000
3)
  Hexadecimal value = 0x20000
    i = 1
    j = 4
    n = i + 4j
      n = 1 + 4 * 4
      n = 1 + 16
      n = 17
   Decimal value = 2^n = 131,072

4)
  n = 16
  Decimal value = 2^n = 65,536
  n = i + 4j where 0 <= i <= 3
    16 = i + 4j
    16 = 0 + 4*4
    i = 0, j = 4
    Hexadecimal: 0x10000

5)
  Decimal value = 256
  n = 8
    8 = i + 4j where 0 <= i <= 3
    i = 0, j = 2
    Hexadecimal value: 0x100

7)
  Hexadecimal value = 0x20
  i = 1, j= 1
  n = i + 4j
  n = 1 + 4*1
  n = 5
  Decimal value = 2^n = 2^5 = 32

n     2^n (Decimal)       2^n (Hexadecimal)
--------------------------------------------
11        2048                 0x800
--------------------------------------------
 7         128                  0x80
--------------------------------------------
13         8192               0x2000
--------------------------------------------
17       131072              0x20000
--------------------------------------------
16        65536              0x10000
--------------------------------------------
 8          256                0x100
--------------------------------------------
 5           32                 0x20
--------------------------------------------

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

Given that x in decimal form is a power of 2: x = 2 ^ n

Binary form of x is 1 followed by n 0's

Hexadecimal form of x is:
  write n in the form of i + 4j where 0 <= i <= 3
  i is the is a key to get the digit of the hexadecimal form, followed by j 0's
  to get the first digit of the hexadecimal form:
    if i = 0: first digit is 1
    if i = 1: first digit is 2
    if i = 2: first digit is 4
    if i = 3: first digit is 8

Example:

x = 2048
x = 2^11

n      = 11
i + 4j = 11 where 0 <= i <= 3
    4*2 = 8 + 3 = 11
i = 3, j = 2;
answer is: 0x800

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.1:

A. 0x8F7A93 to binary

     8    F    7    A    9    3
  1000 1111 0111 1010 1001 0011

  Answer: 100011110111101010010011

B. Binary 1011011110011100 to hexadecimal

  1011 0111 1001 1100
     B    7    9    C

  Answer: 0xB79C

I created a web page that can generate more binary to hexadecimal conversion problems. Previously I had written out some problems, but now there are an unlimited amounts to practice with.

As part of reading this book, I’m writing some exercises. I thought I would benefit from some extra conversion problems. Sorry if there are any mistakes, I double checked, but it to err is to be human.

Here is a conversion chart, a random byte generator if you want to create your own exercises and a converter to check your work.

I. Hexadecimal to Binary


 1) 0xFA01D3
 2) 0x103FED
 3) 0x370EE2
 4) 0xBA5200
 5) 0xDF0E67
 6) 0x149BC0
 7) 0x4E3A27
 8) 0xFA01D3
 9) 0x052CEB
10) 0xEC6DB6
11) 0x6CC122
12) 0xA489C2
13) 0x57915A
14) 0x71B493
15) 0x15A1CC
16) 0xD47E0C
17) 0x0549CA
18) 0x2CF24D
19) 0xB7A7E4
20) 0x16F926

II. Binary to Hexadecimal

 1) 110111111010100010000110
 2) 010101101100010100011011
 3) 100111100101101000101001
 4) 000110000010111001111000
 5) 111011100011000001110011
 6) 100101000000001100100001
 7) 101101011001100011010110
 8) 001010110010100001010011
 9) 000100010010001110100110
10) 101100000011100101100001
11) 110101010010001110011111
12) 001110100011000010000100
13) 011000001110010111000000
14) 111001001111110111011100
15) 110010100000110011110110
16) 111001011111101001110000
17) 010010111100101011000111
18) 011111111110101011001101
19) 101001011001110110000001
20) 010010000110010110111100

III. Solutions

Hexadecimal to Binary

 1) 0xFA01D3

     F    A    0    1    D    3
  1111 1010 0000 0001 1101 0011

 2) 0x103FED

     1    0    3    F    E    D
  0001 0000 0011 1111 1110 1101

 3) 0x370EE2

     3    7    0    E    E    2
  0011 0111 0000 1110 1110 0010

 4) 0xBA5200

     B    A    5    2    0    0
  1011 1010 0101 0010 0000 0000

 5) 0xDF0E67

     D    F    0    E    6    7
  1101 1111 0000 1110 0110 0111

 6) 0x149BC0

     1    4    9    B    C    0
  0001 0100 1001 1011 1100 0000

 7) 0x4E3A27

     4    E    3    A    2    7
  0100 1110 0011 1010 0010 0111

 8) 0xFA01D3

     F    A    0    1    D    3
  1111 1010 0000 0001 1101 0011

 9) 0x052CEB

     0    5    2    C    E    B
  0000 0101 0010 1100 1110 1011

10) 0xEC6DB6

     E    C    6    D    B    6
  1110 1100 0110 1101 1011 0110

11) 0x6CC122

     6    C    C    1    2    2
  0110 1100 1100 0001 0010 0010

12) 0xA489C2

     A    4    8    9    C    2
  1010 0100 1011 1001 1100 0010

13) 0x57915A

     5    7    9    1    5    A
  0101 0111 1001 0001 0101 1010

14) 0x71B493

     7    1    B    4    9    3
  0111 0001 1011 0100 1001 0011

15) 0x15A1CC

     1    5    A    1    C    C
  0001 0101 1010 0001 1100 1100

16) 0xD47E0C

     D    4    7    3    0    C
  1101 0100 0111 0011 0000 1100

17) 0x0549CA

     0    5    4    9    C    A
  0000 0101 0100 1001 1100 1010

18) 0x2CF24D

     2    C    F    2    4    D
  0010 1100 1111 0010 0100 1101

19) 0xB7A7E4

     B    7    A    7    E    4
  1011 0111 1010 0111 1110 0100

20) 0x16F926

     1    6    F    9    2    6
  0001 0110 1111 1001 0010 0110

Binary to Hexadecimal

 1) 110111111010100010000110

  1101 1111 1010 1000 1000 0110
     D    F    A    8    8    6

 2) 010101101100010100011011

  0101 0110 1100 0101 0001 1011
     5    6    C    5    1    B

 3) 100111100101101000101001

  1001 1110 0101 1010 0010 1001
     9    E    5    A    2    9

 4) 000110000010111001111000

  0001 1000 0010 1110 0111 1000
     1    8    2    E    7    8

 5) 111011100011000001110011

  1110 1110 0011 0000 0111 0011
     E    E    3    0    7    3

 6) 100101000000001100100001

  1001 0100 0000 0011 0010 0001
     9    4    0    3    2    1

 7) 101101011001100011010110

  1011 0101 1001 1000 1101 0110
     B    5    9    8    D    6

 8) 001010110010100001010011

  0010 1011 0010 1000 0101 0011
     2    B    2    8    5    3

 9) 000100010010001110100110

  0001 0001 0010 0011 1010 0110
     1    1    2    3    A    6

10) 101100000011100101100001

  1011 0000 0011 1001 0110 0001
     B    0    3    9    6    1

11) 110101010010001110011111

  1101 0101 0010 0011 1001 1111
     D    5    2    3    9    F

12) 001110100011000010000100

  0011 1010 0011 0000 1000 0100
     3    A    3    0    8    4

13) 011000001110010111000000

  0110 0000 1110 0101 1100 0000
     6    0    E    5    C    0

14) 111001001111110111011100

  1110 0100 1111 1101 1101 1100
     E    4    F    D    D    C

15) 110010100000110011110110

  1100 1010 0000 1100 1111 0110
     C    A    0    C    F    6

16) 111001011111101001110000

  1110 0101 1111 1010 0111 0000
     E    5    F    A    7    0

17) 010010111100101011000111

  0100 1011 1100 1010 1100 0111
     4    B    C    A    C    7

18) 011111111110101011001101

  0111 1111 1110 1010 1100 1101
     7    F    E    A    C    D

19) 101001011001110110000001

  1010 0101 1001 1101 1000 0001
     A    5    9    D    8    1

20) 010010000110010110111100

  0100 1000 0110 0101 1011 1100
     4    8    6    5    B    C