Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Fundamentals of Computers: Reema Thareja

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 34

Fundamentals of

Computers

Reema Thareja

© Oxford University Press 2014. All rights reserved.


Chapter 4

Number Systems and


Computer Codes

© Oxford University Press 2014. All rights reserved.


Binary Number System
• Computers are electronic machines that use binary logic.
• This logic uses two different values to represent
the two voltage levels (value 0 for 0 V and value 1 for +5 V).
• The binary number system uses only two digits, 0 and 1.

© Oxford University Press 2014. All rights reserved.


Binary Number System

© Oxford University Press 2014. All rights reserved.


Converting Binary Number into Decimal Form
Convert (1101)2 into a decimal number

Decimal number = 1 × 23 + 1 × 22 + 0 × 21 + 1 × 20

=1×8+1×4+0×2+1×1

=8+4+0+1

= 13

© Oxford University Press 2014. All rights reserved.


Converting Decimal Number into Binary Form
Convert 169 into its binary equivalent

© Oxford University Press 2014. All rights reserved.


Adding Two Binary Numbers
Rules of Binary Addition
•0+0=0
•0+1=1
•1+0=1
• 1 + 1 = 0, and carry 1 to the next more significant bit

© Oxford University Press 2014. All rights reserved.


Adding Two Binary Numbers
Examples of Binary Addition

© Oxford University Press 2014. All rights reserved.


Subtracting Two Binary Numbers
Rules of Binary Subtraction
•0−0=0
•1−0=1
•1−1=0
• 0 − 1 = 1, and borrow 1 from the next more significant bit

© Oxford University Press 2014. All rights reserved.


Subtracting Two Binary Numbers
Examples of Binary Subtraction

© Oxford University Press 2014. All rights reserved.


Subtraction Using Two’s Complement
Calculate 1011 − 1001 using two’s complement

•Subtrahend = 1001

•One’s complement of subtrahend = 0110

•Two’s complement of subtrahend = 0110 + 1 = 0111

•Add the minuend and the two’s complement of the subtrahend

© Oxford University Press 2014. All rights reserved.


Multiplying Two Binary Numbers
Rules of Binary Multiplication
•0 × 0 = 0
•0 × 1 = 0
•1 × 0 = 0
•1 × 1 = 1

© Oxford University Press 2014. All rights reserved.


Multiplying Two Binary Numbers
Examples of Binary Multiplication

© Oxford University Press 2014. All rights reserved.


Dividing Two Binary Numbers

© Oxford University Press 2014. All rights reserved.


Octal Number System

• Base 8 number system which uses digits 0–7

• Extensively used in early mainframe computer systems

• Less popular in comparison to binary and hexadecimal systems

© Oxford University Press 2014. All rights reserved.


Converting Octal Number into Decimal Form

Convert (123)8 into its decimal equivalent

Decimal number = 1 × 82 + 2 × 81 + 3 × 80

= 1 × 64 + 2 × 8 + 3 × 1

= 64 + 16 + 3

= 83

© Oxford University Press 2014. All rights reserved.


Converting Decimal Number into Octal Form
Convert 9890 into octal form

© Oxford University Press 2014. All rights reserved.


Hexadecimal Number System
• Base 16 number system

• Symbols 0–9 represent values zero to nine, and A, B, C, D, E, F (or


a–f ) represent values 10–15

• Prefix 0x is used for numbers represented in hexadecimal system

© Oxford University Press 2014. All rights reserved.


Converting Hexadecimal Number into Decimal Form

Convert 0x312B into its equivalent decimal value

Decimal number = 3 × 163 + 1 × 162 + 2 × 161 + B × 160

= 3 × 4096 + 1 × 256 + 2 × 16 + B × 1

= 12288 + 256 + 32 + 11

= 12587

© Oxford University Press 2014. All rights reserved.


Converting Decimal Number into Hexadecimal Form

Convert 1239 into Hexadecimal Form

© Oxford University Press 2014. All rights reserved.


Converting Hexadecimal Number into Binary Form

• Write the 4-bit binary representation of each hexadecimal digit


• Convert 0xABCD into its binary equivalent

(ABCD) = (1010 1011 1100 1101)


16 2

© Oxford University Press 2014. All rights reserved.


Converting Binary Number into Hexadecimal Form

• Pad the binary number with leading zeroes (if necessary), so that it
contains multiples of 4 bits
• Convert the binary number 01101110010110 into its hexadecimal
equivalent
▪ After padding the binary number is 0001 1011 1001 0110
▪ Substitute the appropriate hexadecimal digits for a group of
four binary digits
▪ The equivalent hex number = 1B96

© Oxford University Press 2014. All rights reserved.


Converting Hexadecimal Number into Octal Form

• Convert the hexadecimal number into its binary equivalent


• Convert the binary number into its equivalent octal number

• Convert (A1E)16 into its octal equivalent

▪ Convert (A1E)16 into its binary equivalent (10100001

1110)2

▪ Now divide the binary number into groups of 3 binary


bits and convert each group into its equivalent octal
number. Thus, we have (5036)8

© Oxford University Press 2014. All rights reserved.


Converting Octal Number into Hexadecimal Form

• Convert the octal number into its binary equivalent


• Convert the binary number into hexadecimal form

• Convert (567)8 into its hexadecimal equivalent

▪ (567)8 = (101 110 111)2

▪ Form groups of 4 binary bits

▪ (Left pad if required) and convert each group into


hexadecimal number. Thus, we have (177)16

© Oxford University Press 2014. All rights reserved.


Working with Fractions
Convert (10110.1110)2 into decimal

(10110.1110)2 = 1 × 24 + 0 × 23 + 1 × 22 + 1 × 21 + 0 ×20 + 1 × 2−1


+ 1 × 2−2 + 1 × 2−3 + 0 × 2−4

= 1 × 16 + 0 × 8 + 1 × 4 + 1 × 2 + 0 × 1 +
1 × 1/2 + 1 × 1/4 + 1 × 1/8 + 0 × 1/16

= 16 + 0 + 4 + 2 + 0 + 0.5 + 0.25 + 0.125 + 0

= 22.875

© Oxford University Press 2014. All rights reserved.


Working with Fractions
Convert (127.35)8 into decimal

(127.35)8 = 1 × 82 + 2 × 81 + 7 × 80 + 3 × 8−1 + 5 × 8−2

= 1 × 64 + 2 × 8 + 7 × 1 + 3 × 1/8 + 5 × 1/64

= 64 + 16 + 7 + 0.375 + 0.078125

= 87.453125

© Oxford University Press 2014. All rights reserved.


Signed Number Representation
• Required to encode negative numbers in the binary
• Three widely used techniques are:
✓ In Sign-and-magnitude, MSB is set to 0 for a positive number
or zero, and set to 1 for a negative number. The other bits
denote the value or the magnitude of the number.
✓ In One’s Complement, first write the binary representation of
the number’s positive counterpart and then negate each bit.
✓ In Two’s Complement, negate all the bits in the binary
representation and then add 1 to the result.

© Oxford University Press 2014. All rights reserved.


BCD Code
• Used for encoding decimal numbers
• Digits 0-9 are used
• Each digit is represented by its own binary sequence of 4 bits
• For example, decimal 7 is 0111 in BCD
• Allows easy conversion to decimal digits for printing or display
• Allows faster decimal calculations

© Oxford University Press 2014. All rights reserved.


BCD Code
• Two types of BCD numbers are—unpacked and packed BCD
✓ In unpacked BCD representation, only one decimal digit is
represented per byte. The digit is stored in the lower
nibble, and the higher nibble is not relevant to the value of
the represented number. For example, Decimal 17 = 0000
0001 0000 0111.
✓ In packed BCD representation, two decimal digits are
stored in a single byte. For example, Decimal 17 = 0001
0111 (in BCD).

© Oxford University Press 2014. All rights reserved.


ASCII
• Stands for American Standard Code for Information Interchange
• Seven-bit character code
• ASCII characters are examples of unpacked BCD numbers

• Values in ASCII codes are represented as their 4-bit binary


equivalents stored in the lower nibble, while the upper nibble
contains 011
• Most common format for text files in computers and on the
Internet

© Oxford University Press 2014. All rights reserved.


EBCDIC
• Stands for Extended Binary Coded Decimal Interchange Code
• Eight-bit character-encoding technique used on mainframe
• Supports a wider range of control characters than ASCII
• EBCDIC characters are similar to ASCII characters. While the lower
nibble contains the 4-bit binary equivalent the upper nibble is
padded with 1111, instead of 011

© Oxford University Press 2014. All rights reserved.


Excess-3 Code
• Each decimal digit is the 4-bit binary equivalent with 3 (0011)
added

© Oxford University Press 2014. All rights reserved.


Gray Code
• A minimum change code, in which only 1 bit in the code changes
from one code to the next
• Non-weighted code
• Steps to obtain Gray code:
▪ Copy the MSB of the binary code as the MSB of the Gray
code
▪ Repetitively add MSB and the bit next to the MSB to get the
corresponding bit for the Gray code

© Oxford University Press 2014. All rights reserved.


Unicode
• Can represent characters (including punctuation marks,
mathematical symbols, technical symbols, and arrows) as integers
• Has several character encoding forms:
▪ UTF-8: Uses only 8 bits to encode English characters. This format is
widely used in email and on the Internet.
▪ UTF-16: Uses 16 bits to encode the most commonly used
characters. It can represent more than 65,000 characters.
▪ UTF-32: Uses 32 bits to encode the characters. It can represent
more than 100,000 characters.

© Oxford University Press 2014. All rights reserved.

You might also like