0% found this document useful (0 votes)
45 views10 pages

Appendix F

The document provides an overview of various number systems used in computing, including binary, octal, decimal, and hexadecimal. It explains how computers use binary internally and how to convert between these number systems. Additionally, it details the positional value of digits in decimal and binary systems, as well as methods for converting between decimal and binary or hexadecimal formats.

Uploaded by

Ravi Shankar Jha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views10 pages

Appendix F

The document provides an overview of various number systems used in computing, including binary, octal, decimal, and hexadecimal. It explains how computers use binary internally and how to convert between these number systems. Additionally, it details the positional value of digits in decimal and binary systems, as well as methods for converting between decimal and binary or hexadecimal formats.

Uploaded by

Ravi Shankar Jha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd

Appendix F

Number Systems

binary

0, 1

octal 0, 1, 2, 3, 4, 5, 6, 7

decimal 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

hexdecimal 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rig
hts reserved. 0132130807 1
Number Systems
Computers use binary numbers internally because storage devices
like memory and disk are made to store 0s and 1s. A number or a
text inside a computer is stored as a sequence of 0s and 1s. Each 0
and 1 is called a bit, short for binary digit. The binary number
system has two digits, 0 and 1.

Binary numbers are not intuitive, since we use decimal numbers in


our daily life. When you write a number like 20 in a program, it is
assumed to be a decimal number. Internally, computer software is
used to convert decimal numbers into binary numbers, and vice
versa.

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rig
hts reserved. 0132130807 2
Number Systems, cont.
The digits in the decimal number system are 0, 1, 2, 3, 4, 5, 6, 7, 8,
and 9. A decimal number is represented using a sequence of one or
more of these digits. The value that each digit in the sequence
represents depends on its position. A position in a sequence has a
value that is an integral power of 10. For example, the digits 7, 4, 2,
and 3 in decimal number 7423 represent 7000, 400, 20, and 3,
respectively, as shown below: 7 4 2 3 7 10  4 10  2 10  3 10 3 2 1 0

103 102 101 100 7000  400  20  3 7423

The decimal number system has ten digits and the position values
are integral powers of 10. We say that 10 is the base or radix of the
decimal number system. Similarly, the base of the binary number
system is 2 since the binary number system has two digits and the
base of the hex number system is 16 since the hex number system
has sixteen digits.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rig
hts reserved. 0132130807 3
Number Systems, cont.
Binary numbers tend to be very long and cumbersome. Hexadecimal
numbers are often used to abbreviate binary numbers. The
hexadecimal number system has 16 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
A, B, C, D, E, and F. The letters A, B, C, D, E, and F correspond to
the decimal numbers 10, 11, 12, 13, 14, and 15.

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rig
hts reserved. 0132130807 4
Binary Numbers => Decimals
Given a binary number bnbn  1bn  2...b 2b1b 0
the equivalent decimal value is

bn 2 n  bn  1 2 n 1  bn  2 2 n 2  ...  b 2 2 2  b1 21  b 0 2 0

10 in binary 1 21  0 = 2 in decimal

1000 in binary 1 23  0 2 2  0 2  0 = 8 in decimal

10101011 = 171 in
1 2 7  0 2 6  1 25  0 2 4  1 23  0 2 2  1 2  1
in binary decimal

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rig
hts reserved. 0132130807 5
Decimals => Binary
To convert a decimal number d to a binary number is to find the
binary digits.. bn, bn  1, bn  2,..., b 2, b1, b 0 such that

d bn 2 n  bn  1 2 n 1  bn  2 2 n 2  ...  b 2 2 2  b1 21  b 0 2 0


These numbers can be found by successively dividing d by 2 until the quotient
is 0. The remainders are bn, bn  1, bn  2,..., b 2, b1, b 0

For example, the decimal number 123 is 1111011 in binary. The conversion is
conducted as follows:

0 1 3 7 15 30 61 Quotient
2 1 2 3 2 7 2 15 2 30 2 61 2 123
0 2 6 14 30 60 122
1 1 1 1 0 1 1 Remainder

b6 b5 b4 b3 b2 b1 b0

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rig
hts reserved. 0132130807 6
Windows Calculator
The Windows Calculator is a useful tool for performing number
conversions. To run it, choose Programs, Accessories, and
Calculator from the Start button.

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rig
hts reserved. 0132130807 7
Hexadecimals => Decimals
The hexadecimal number system has sixteen digits: 0, 1, 2, 3, 4, 5,
6, 7, 8, 9, A, B, C, D, E, and F. The letters A, B, C, D, E, and F
correspond to the decimal numbers 10, 11, 12, 13, 14, and 15.
Given a hexadecimal number hnhn  1hn  2...h 2 h1h 0
The equivalent decimal value is

hn 16 n  hn  1 16 n  1  hn  2 16 n  2  ...  h 2 16 2  h1 161  h 0 160

7F in hex 7 161  15 = 127 in decimal


3 2
FFFF in hex 15 16  15 16  15 16  15 = 65535 in decimal

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rig
hts reserved. 0132130807 8
Decimals => Hexadecimal
To convert a decimal number d to a hexadecimal number is to find
the hexadecimal digits hn,
hn, hhn-1,
n  1, hn hn-2, ...2, h1, h 0 such that
 2,..., h

d hn 16n  hn  1 16n  1  hn  2 16n  2  ...  h 2 162  h1 161  h 0 160

These numbers can be found by


successively dividing d by 16 until the 0 7 Quotient
quotient is 0. The remainders are 16 7 16 123
0
h 0, h1, h 2,..., hn  2, hn  1, hn 112
7 11 Remainder
For example, the decimal number 123 is
7B in hexadecimal. The conversion is h1 h0

conducted as follows:

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rig
hts reserved. 0132130807 9
Hexadecimal  Binary
Binary Hex Decimal
To convert a hexadecimal number to a binary
0000 0 0 number, simply convert each digit in the
0001 1 1 hexadecimal number into a four-digit binary
0010 2 2 number.
0011 3 3
0100 4 4 To convert a binary number to a hexadecimal,
0101 5 5 convert every four binary digits from right to
0110 6 6 left in the binary number into a hexadecimal
0111 7 7 number. For example,
1000 8 8
1001 9 9
1010 A 10
1011 B 11 1110001101
1100 C 12
1101 D 13
1110 E 14 3 8 D
1111 F 15
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rig
hts reserved. 0132130807 10

You might also like