Skip navigation

Tag Archives: decimal

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

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

These are notes from the book I am currently reading. These notes are available at Google Code.

Hexadecimal notation

-----------------------------------------------------------------------------------------------------------------------------------
| Hex Digit       |    0 |    1 |    2 |    3 |    4 |    5 |    6 |    7 |    8 |    9 |    A |    B |    C |    D |    E |    F |
-----------------------------------------------------------------------------------------------------------------------------------
| Decimal value   |    0 |    1 |    2 |    3 |    4 |    5 |    6 |    7 |    8 |    9 |   10 |   11 |   12 |   13 |   14 |   15 |
-----------------------------------------------------------------------------------------------------------------------------------
| Binary value    | 0000 | 0001 | 0010 | 0011 | 0100 | 0101 | 0110 | 0111 | 1000 | 1001 | 1010 | 1011 | 1100 | 1101 | 1110 | 1111 |
-----------------------------------------------------------------------------------------------------------------------------------

Tips:

Memorize decimal equivalments of hex digits, A, C, and F, and the hex values of B, D and E can be translated “by computing their values relative to the first three”

If a binary number is not a multiple of for pad with 0’s on the left until it is.

Given 0x173A4C:

---------------------------------------------------------
| Hexadecimal |    1 |    7 |    3 |    A |    4 |    C |
---------------------------------------------------------
| Binary      | 0001 | 0111 | 0011 | 1010 | 0100 | 1100 |
---------------------------------------------------------

Given 1111001010110110110011:

Break into four

1111 0010 1011 0110 1100 11

Pad with 0’s on left to get multiple of four:

0011 1100 1010 1101 1011 0011

Conversion:

---------------------------------------------------------
| Hexadecimal |    3 |    C |    A |    D |    B |    3 |
---------------------------------------------------------
| Binary      | 0011 | 1100 | 1010 | 1101 | 1011 | 0011 |
---------------------------------------------------------

Vertical conversion table:

Dec   Hex   Binary
0       0     0000
1       1     0001
2       2     0010
3       3     0011
4       4     0100
5       5     0101
6       6     0110
7       7     0111
8       8     1000
9       9     1001
10      A     1010
11      B     1011
12      C     1100
13      D     1101
14      E     1110
15      F     1111