Docsity

1's and 2's complement, Essays (university) of Computer Science

Partial preview of the text

Download 1's and 2's complement and more Essays (university) Computer Science in PDF only on Docsity!

Binary Number

System & Boolean

Logic

Objectives

Describe the difference between analog signal and

digital signal

Introduce the binary number system and binary

arithmetic

Discuss how to convert between binary and

decimal

Explain how various data (positive integers,

characters, colors) are represented in computers

Reproduce the truth tables for the AND, OR, NOT,

and XOR Boolean operations and logic gates

Trace the logic of the adder circuits composed of a

few simple gates: half-adder, full-adder, multiple-

bit adder

Analyze and do some simple design of logic circuits

Instructor: M. Shahzad Jaffar

Binary System in a Digital

Computer

 Computers are made up of millions of switches

 Each switch has two states, “on” or “off”

Thus, binary system is a nature and easiest

way for a computer to represent information

and implement operations

Number Systems

Number system

Any system of representing numbers. Also called

numeral system

The base of any number system is the number of digits

in the system

 The number systems most commonly used in

are:

Decimal - 10 digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Binary - 2 digits 0, 1

Octal - 8 digits 0, 1, 2, 3, 4, 5, 6, 7

Hexadecimal - 16 digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C,

D, E, F

Binary: base-2 number

system

 Formula: ∑DIGIT * 2

POSITION

Octal and Hexadecimal

Octal - base 8 number system

Hexadecimal - base 16 number system

E.g., (for example)

2610 = 110102 = 328 = 1A

Binar

y

Octal Decima

l

Hexa-

decimal

1010 12 10 A
1011 13 11 B
1100 14 12 C
1101 15 13 D
1110 16 14 E
1111 17 15 F

Decimal Integer to Binary

 Convert a positive decimal

integer to binary using

repeated division

Step 1 - divide the value by two

and record the remainder

Step 2 - continue to divide the

quotient by two and record the

remainder, until the newest

quotient becomes zero

Step 3 - the binary

representation is the remainders

listed from bottom to top in the

order they were recorded

E.g., what's the

binary for

integer 13?

13 ÷ 2 = 6 ··· 1

6 ÷ 2 = 3 ··· 0

3 ÷ 2 = 1 ··· 1

1 ÷ 2 = 0 ··· 1

Answer: 1 1 0 1

Quotient

Reminder

Divisor

Dividend

Exercise: Real Numbers to

Binary

 A real number is a number that has a decimal

point (called floating point number in

computing languages)

Convert decimal 13.375 to binary:

 13 = 1101

 0.375 = 0.

 13.375 = 1101.

 More examples:

133.3 =?

  • 1345.57 =?

Standardize the representation of real

numbers

Unfortunately,
floating is not
represented
like this in
computer

Standardize Real Number

Representation

 Normalized representation of real numbers:

20,000  2.0 x 10

4; -0.0034  -3.4 x 10-

101.01  1.0101x22; -0.00101  - 1.01x2-

The integer part of a standard floating point number is always “1”, it is omitted in the representation

Each real number has 3 parts: sign, exponent, fraction

IEEE 754 (reference [4]): IEEE Standard for Floating-Point Representation of
Normalized Binary Numbers
-3.4 is mantissa
-3 is exponent

Instructor: M. Shahzad Jaffar

Binary Arithmetic

 Rules of Binary

Multiplication

0 x 0 = 0

0 x 1 = 0

1 x 0 = 0

1 x 1 = 1, and no carry or

borrow bits

E.g.,

0 0 1 0 1 0 0 1 (

10 )

x 0 0 0 0 0 1 1 0 (6 10 )

0 0 0 0 0 0 0 0

0 0 1 0 1 0 0 1

0 0 1 0 1 0 0 1

0 0 1 1 1 1 0 1 1 0 (246 1 0

)

Binary Division:

repeated process of

subtraction

E.g.,

1 1 0 1 1 (

1 0

)

1 0 1 ) 1 0 0 0 0 1 1 1 (135 10 )

(5 10 ) - 1 0 1

1 1 0

- 1 0 1

0 1 1

- 0

1 1 1

- 1 0 1

1 0 1

- 1 0 1

function divide(N, D)

R := N

while R ≥ D do

Q := Q + 1

R := R - D end

return (Q, R) end

Bytes Representing Signed

Integers

1's complement

 representation for signed integers

Designed to simplify the binary arithmetic, allowing the

computer to perform all arithmetic operations using only

addition

 The 1's complement of a number is found by changing all

1's to 0's and all 0's to 1's. This is called as taking

complement or 1's complement. Example of 1's

Complement is as follows.

Bytes Representing Signed

Integers

2’s

complement:-

 Example:

 Convert binary number

111001101 to 2’s

complement

 Method

 2’s complement of a

binary no can be

obtained by two step

process

Trick : 2’s

complement can be

represented by keeping all

lower significant bits till first

Step 1

1’s complement of

number N = 000110010

Step 2

1’s complement + 1

Answer

2’s complement of a

binary no 111001101 is

Instructor: M. Shahzad Jaffar

Bytes Representing Signed

Integers

2’s complement:-

Bytes Representing Text

 Each character (letter,

punctuation, etc.) is

assigned a unique binary

number

ASCII - American Standard

Code for Information

Exchange (primarily for

English)

Unicode : represent the major

symbols used in languages

world side

E.g.,

Text: H e l l o!
ASCII: 48 56 6C 6C 6F 21

 For more help

http://www.electrical4u.com/

alphanumeric-codes-ascii-cod

e-ebcdic-code-unicode/

Byte Representing Colors

 A monitors screen is

divided into a grid of

small unit called pixels

 The more pixels per inch,

the better the resolution ,

the sharper the image

 All colors on the screen

are a combination of red,

green and blue (RGB),

just at various intensities

“True color” systems

require 3 bytes or 24 bits

per pixel

There are also 4-bit and

8-bit color systems