SlideShare ist ein Scribd-Unternehmen logo
1 von 194
NUMBER SYSTEM
Part 1
Objectives - To understand
3.1 Analyses how numeric data are represented
in
computers
I.
II.
III.
IV.

V.

Decimal representation of numbers (Signed and Unsigned)
Integers
Fixed Point and Floating-Point numbers
Number systems used in computing
Binary, Octal, Hexa-decimal logic operation
Conversions among number systems
Introduction
Introductio
n
A number system defines a set of values used to represent a quantity.
The study of numbers is not only related to computers. We apply numbers
everyday, and knowing how numbers work, will give us an insight of how
computers manipulate and store numbers.

A number is a mathematical object used in counting and measuring. It is

used in counting and measuring. Numerals are often used for labels, for
ordering serial numbers, and for codes like ISBNs. In mathematics, the
definition of number has been extended over the years to include such
numbers as zero, Positive numbers , Negative numbers , Integers
numbers , Rational numbers, Irrational numbers, Whole number and
complex numbers.
Certain procedures which take one or more numbers as input and produce a
number as output are called numerical operation.
Types of numbers
Complex number:- The complex numbers consist of all numbers of the form
(a+bi) ; Where a and b are real numbers and i=0.1
Ex :- 2+5i , 3+3i , … . .. . . . , 14+20i

Real Numbers (R) :- The real numbers include all of the measuring
numbers
Ex :- -69 , -2 , -1.5 , +5 …+ 7.5 . .. . . . , +14

Rational Numbers (Q) :- A rational number is a number that can be expressed as
a fraction with an integer and a non-zero natural number denominator

Ex :- -25 , -15/10 , 0 , 0.05 , 0.2 , 7/3 , 25 ,36

Irrational Numbers:- A decimal that can be written as a fraction either ends
(terminates)or forever repeats about which we will see in detail further.
Ex – π =3.14159365358979
Natural numbers (N) :- All positive numbers (Counting numbers)
started with 1.However in the 19th century, mathematicians started including 0 in the set of natural numbers.

Ex :- 0,1,2,3,4,……,55 ,105 . .. . . .
Types of numbers
Integers (Z):- Integers are the number which includes positive and negative
numbers. Negative numbers are usually written with a negative sign
(also called a minus sign)in front of the number they are opposite
of .When the set of negative numbers is combined with the
natural numbers zero, the result is the set of integer numbers
Ex :- -25 , -15 , +0 , +25 , +36
Fractions :- This is a type of a rational number. Fractions are written as two
numbers (m/n), the numerator (m) and the denominator(n)
1. Fixed point Number
2.Floating point number
Fixed point number :-

Involving or being a mathematical notation(as in a decimal system)
in which the point separating whole numbers and fractions is fixed

A fixed point number has a specific number of bits (or digits) reserved
for the integer part (the part to the left of the decimal point) and a
specific
number of bits reserved for the fractional part (the
part tothe
right of the decimal point). No matter how large or small your number
is, it will always use the same number of bits for each portion.
For example:- if your fixed point format was in decimal IIIII.FFFFF then

the largest number you could represent would be 99999.99999 and
the smallest would be 00000.00001. Every bit of code that processes
such numbers has to have built-in knowledge of where the decimal
point is.

123.56
25.23
8955.3
0.5
0.0098

A fixed point number just means that there are a fixed number of
digits after the decimal point.
Floating point number :A floating point number does not reserve a specific number of bits for the integer part
or the fractional part. Instead it reserves a certain number of bits for the number
(called the mantissa or significant ) and a certain number of bits to say where within
that number the decimal place sits (called the exponent).
For example:-So a floating point number that took up 10 digits with
2 digits reserved for the exponent might represent a largest value of
9.9999999e+50 and a smallest value of 0.0000001e-49.

1.2 × 10 2
35.02 × 10 80
0.258 × 10 -14 / 2.58 × 10 -15 / 25.8 × 10 -16

A floating point number allows for a varying number of digits after the decimal
point.
Types of numbers
Precision({Í ý<) and Accuracy (ùÚØ<÷À]õ$<

•Precision is the measure of how closely individual measurements
agree with one another.
• Accuracy is how closely individual measurements with the
correct value.
Significant Digits( µ<µ&&Ú &‘ç]$‘æ×)
"Significant Digits", also called "Significant Digits of Precision ", are the digits in
a number starting with the first non-zero digit and ending with the last non-zero digit.
Those digits can be anywhere relative to the decimal.

Non-zero digits are always significant.
22 has two significant digits,
22.3 has three significant digits.

With zeroes, the situation is more complicated
a. Zeroes placed before other digits are not significant;
0.046 has two significant digits.
b. Zeroes placed between other digits are always significant;
4009 kg has four significant digits.
c. Zeroes placed after other digits but behind a decimal point are significant;
7.90 has three significant digits.
85.00 g has four significant digits
9.000 000 000 mm has 10 significant digits
Significant Digits
d. Zeros at the end of a number but to the left of a decimal may or may not be
significant. If such a zero has been measured, or is the first estimated digit, it
is significant. On the other hand, if the zero has not been measured or
estimated but is just a placeholder, it is not significant. A decimal placed after
the zeros indicates that they are significant
1.
2000 m may contain from one to fou r significant digits, depending on how
many
zeros are placeholders. For measurements given in this text , assume that 2000 has one
significant digits.
2. 2000 . m contains four significant digits, indicated by the presence of the
decimal point
3.1000.0 has five significant digits (the ".0" tells us something interesting about the presumed
accuracy of the measurement being made: that the measurement is accurate to the tenths place,
but that there happen to be zero tenths)
For example:- in the number 8200, it is not clear if the zeroes are significant or not. The
number of significant digits in 8200 is at least two, but could be three or four. To avoid
uncertainty, use scientific notation to place significant zeroes behind a decimal point:
i.8.200 *103 has four significant digits
ii.8.20 *103 has three significant digits
iii.8.2 *103 has two significant digits
Significant Digits
Scientific notation - All digits expressed before the exponential term are
significant.

5.060 x 10-3 m has four sig figs.
9.00 x 102 g has three sig figs.
Most Significant Digit

Significant Digit

•The MSD in a number is the digit that has the greatest effect on that number.
Highest power of base weighting
The digits on the left hand side are called the high-order digits (higher powers of 10)

Least Significant Digit (MSD and LSD)

• The LSD in a number is the digit that has the least effect on that number.
• Lowest power of base weighting
• Digits on the right hand side are called the low-order digits (lower powers of 10).
Significant Digit
You can easily see that a change in the MSD will increase or decrease the value of the
number the greatest amount. Changes in the LSD will have the smallest effect on the
value. The nonzero digit of a number that is the farthest LEFT is the MSD, and the
nonzero digit farthest RIGHT is the LSD, as in the following example
Key principle of numbering systems
Radix point (´ÕÙæ ÙæßÂ]× )
Divides fractional portion from the whole portion of a number

Weighting Factor ( ýØ &$øæ× )
A multiplier value is used in each column position of a number . It represents
the weight factor. Its value determines how many times the Base value is
multiplied by itself thus giving the placeholders seen below from right to left
labelled as "Ones", "Tens", "Hundreds", "Thousands", "Ten Thousands" and so
on. . .
OSITIONAL (&ßö$ùÛ×)NUMBER SYSTEMS
In a positional number system, the position a symbol occupies in the number
determines the value it represents. In this system, a number represented as:

In our decimal number system, the value of a digit depends on its place, or position, in the number. Each
place has a value of 10 times the place to its right.
A number in standard form is separated into groups of three digits using commas. Each of these groups is
called a period.
OSITIONAL (&ßö$ùÛ×)NUMBER SYSTEMS
OSITIONAL (&ßö$ùÛ×)NUMBER SYSTEMS
OSITIONAL (&ßö$ùÛ×)NUMBER SYSTEMS
In a positional number system, the position a symbol occupies in the number
determines the value it represents. In this system, a number represented as:

has the value of:

in which S is the set of symbols, b is the base (or radix).
Key principle of numbering systems
Positional value significance
Gives weight each digit contributes to the number’s overall value

Ex:-1.Steps for base 10
Determine positional value of each digit by raising 10 to position within number
2. Steps for base 2
Determine positional value of each digit by raising 2 to position within number
Calculate Position Value and Weighed
General procedure (any base)
 Calculate position value of the number by raising the base value to the
power
of the position
 Multiply positional value by digit in that position
 Add each calculated value together
Number Representations
Integer numbers are those numbers which do not have fractional
parts. Integer numbers include both positive numbers and
negative numbers. They can be handled using any of the following
representations
Unsigned notation
Signed magnitude notion

Unsigned notation
An unsigned integer is an integer that can never be negative and
can take only 0 or positive values. Its range is between 0 and
positive infinity. All unsigned numbers are Positive
0 , 1 , 2 , 3 , 4 , . . . . , 1598 , . . . .
Range = 0 to (2n – 1) ; n is the number of bits used to store the unsigned integer.
Numbers with values GREATER than (2n – 1) would require more bits. If you try to store
too large a value without using more bits, OVERFLOW will occur.
Example: On a system that stores unsigned integers in 16-bit words:
Range = 0 to (216 – 1) = 0 to 65535
Therefore, you cannot store numbers larger than 65535 in 16 bits.
Unsigned representation
Advantages:
1.One representation of zero
2.Simple addition
Disadvantages :
1.Negative numbers can not be represented.
2.The need of different notation to represent negative
numbers.
Signed notation


Until now we've been concentrating on unsigned numbers. In real life we
also need to be able represent signed numbers (like : -12, -45, +78).



A signed number MUST have a sign (+/-). A method is needed to represent
the sign as part of the binary representation. All signed numbers are
negative and positive
-1.5× 103 , - 25 , -9.6×10-4 , +0 , +5.7×10-4 , +0.5 , +98 , +4.6 ×103

Range =-(2(n-1) – 1) to +(2(n-1) – 1) ; n is the number of bits used to store the sign/magnitude integer
Numbers with values GREATER than +(2(n-1) – 1) and values LESS than -(2(n-1) – 1) would require
more bits. If you try to store too large/too small a value without using more bits, OVERFLOW will
occur.
Example: On a system that stores unsigned integers in 16-bit words:
Range
= -(2(16-1) – 1) to +(2(16-1) – 1) = -(2(15) – 1) to +(2(15) – 1)
= -32767 to +32767
Therefore, you cannot store numbers larger than 32767 or smaller than -32767 in 16 bits.
Sign Representation
Advantages:

Represents positive and negative numbers

Disadvantage :

 Arithmetic operations are difficult.
Addition and subtractions are difficult.

Signs and magnitude, both have to carry out the required
operation.
They are two representations of 0 (Binary number system)
00000000 = + 010
10000000 = - 010
To test if a number is 0 or not, the CPU will need to see
whether it is 00000000 or 10000000.
0 is always performed in programs.

Therefore, having two representations of 0 is inconvenient.
Summary
Binary
Unsigned

No. of bits

Sign-magnitude

Min

Max

Min

Max

1

0

1

2

0

3

-1

1

3

0

7

-3

3

4

0

15

-7

7

5

0

31

-15

15

6

0

63

-31

31

Etc.
No. of bits

n

Binary
Unsigned

Sign-magnitude

Min

Max

0

2 -1

n

Min

n-1

-(2

– 1)

Max

n-1

2

-1
Numeric
Representation
s
Numbering Systems



Integer ……………. Z
Decimal……………
Base 10
(N10 )



Binary ……………..

Base 2 (N2 )



Octal ……………….

Base 8 (N8 )



Hexadecimal …….

Base 16


Integer
Integer

A number with no fractional part Includes the
counting numbers {1, 2, 3, ...}, zero {0}, and the
negative of the counting numbers {-1, -2, -3, ...}
You can write them down like this: {..., -3, -2, -1, 0,
1, 2, 3, ...}
Examples of integers: -16, -3, 0, 1, 198
Decimal
Decimal Number System



The decimal system is a base-10 system.
There are 10 distinct digits (0 to 9) to represent any quantity.
10 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }




For an n-digit number, the value that each digit represents
depends on its weight or position.
Digit Position
Integer & fraction 123.456



The weights are based on powers of 10.
Weight = (Base)

Position

1024 = 1*103 + 0*102 + 2*101 + 4*100 = 1000 + 20 + 4
Positional value example: 436.95
To the left of the radix point : 4 in position two / 3 in position one / 6 in position zero
To the right of the radix point: 9 in position negative one / 5 in position negative two
Decimal Number System


Base (also called radix) = 10




Digit Position




Integer & fraction
Weight = (Base)

0

-1

-2

7 4

10

1

0.1 0.01

10

2

0.7 0.04

Position

Sum of “Digit x Weight”

Formal Notation

1

5 1 2
100

Magnitude




2

Digit Weight




10 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }

500

d2*B2+d1*B1+d0*B0+d-1*B-1+d-2*B-2

(512.74)10
Example
For D = 52.946
Standard decimal representation
Uses the ten numbers from 0 to 9
Each column represents a power of 10

Fixed-point representation
Uses the two numbers from 0 to 9
Every column represents a power of 10
Positional Value (cont’d.)

Positional values for a base 10 number
Whole Numbers (Radix = 10):
123410 = 1 × 103 + 2 × 102 + 3 × 101 + 4 × 100
With Fractional Part (Radix = 10):
36.7210 = 3 × 101 + 6 × 100 + 7 × 10-1 + 2 × 10-2
General Case (Radix = R):
(S1S0.S-1S-2)R =
S1 × R1 + S0 × R0 + S-1 × R -1 + S-2 × R-2

Reals
Practice (base 10)
1) 258 = 2.58 x 10 2
Mantissa = 258
Radix = 10
Exponent = 2

3) One billion =1,000,000,000 =1 x 109




significand or mantissa: 1
base or radix: 10
exponent: 9

(Scientific notation )

4) 1999 =1.999 x 103
significand or mantissa: 1999
base or radix: 10
exponent: 3
=19.99 x 102
=199.9 x 101
2) 24.25 = 2.425 x 10 1
=Mantissa = 2425
=Radix = 10
=Exponent = 1

2) The following shows the place values for the integer +224 in the decimal
system.

Note that the digit 2 in position 1 has the value 20, but the same digit in position
2 has the value 200. Also note that we normally drop the plus sign, but it is
implicit.
Example
The following shows the place values for the decimal number −7508. We have
used 1, 10, 100, and 1000 instead of powers of 10.

(

) Values

Note that the digit 2 in position 1 has the value 20, but the same digit in position
2 has the value 200. Also note that we normally drop the plus sign, but it is
implicit.

Example
The following shows the place values for the real number +24.13.
Binary
Binary Number Systems


The binary system is a base-2 system.



There are 2 distinct digits (0 and 1) to represent any quantity.
2 digits { 0, 1 }, called binary digits or “bits”

• 0 = represents no value
• 1 = represents a unit value


For an n-digit number, the value of a digit in each column depends on its
position.



The weights are based on powers of 2.

Weight = (Base) Position

1011 2 = 1*2 3 + 0*2 2 + 1*2 1 + 1*2 0 =8+2+1 =11 10
Binary Number System


Weights

4

Weight = (Base) Position


Magnitude



Formal Notation
Groups of bits

1

1/2 1/4

1 0 1

0

1

2

-1

-2

1

0

=1 *2 2 +0 *2 1 +1 *2 0 +0 *2 -1 +1 *2 -2

Sum of “Bit x Weight”


2

=(5.25) 10

=(101.01)2
4 bits = Nibble
8 bits = Byte

1011
11000101
Binary Number System
Binary number

Value encoded by the binary number
0 0×2 0 = 0
1 1×2 0 = 1
10 1×2 1 + 0 ×2 0 = 2
11 1×2 1 + 1 ×2 0 = 3
1010 1×2 3 + 0×22 + 1×21 + 0×20 = 8 + 2 = 10

Base-2 scientific notation
1) 2.25ten = 10.01two = 10.01two x 20 = 1.001two x 21  normalized

Numbers are usually normalized which means that the leading bit is always a 1.

2) 1100.101two
Digit

1

1

0

0

.

1

0

1

Weight 23

22

21

20

Binary decimal
Point

2-1

2-2

2-3
Standard binary representation
Uses the two numbers from 0 to 1
Every column represents a power of 2

Fixed-point representation
Uses the two numbers from 0 to 1
Every column represents a power of 2
Positional Value

1)Positional value of the binary number 10112

Rightmost position: positional value of the base (2) raised to the 0 power
First Positional value: 1 (1 * 20)
Next position: value of 2 raised to the power of 1 (1 * 21)
Next position: 2 squared (0 * 22)
Next position: 2 to the third (1 * 23)
(1 * 20) + (1 * 21) + (0 * 22) + (1 * 23)
2)Positional value of the binary number 1011.0112 as follows
Whole Numbers (Radix = 2):
10112 = 1 × 23 + 0 × 22 + 1 × 21 + 1 × 20
With Fractional Part (Radix = 2):
11.012 = 1 × 21 + 1 × 20 + 0 × 2-1 + 1 × 2-2
General Case (Radix = R):
(S1S0.S-1S-2)R =
S1 × R1 + S0 × R0 + S-1 × R -1 + S-2 × R-2

Real's
Example
The following shows that the number (11001)2 in binary is the same as 25 in
decimal. The subscript 2 shows that the base is 2.

The equivalent decimal number is N = 16 + 8 + 0 + 0 + 1 = 25.

Example
The following shows that the number (101.11)2 in binary is equal to the number
5.75 in decimal.
Octal
Octal Number Systems


Octal and hexadecimal systems provide a shorthand way to deal with the
long strings of 1’s and 0’s in binary.



Octal is base-8 system using the digits 0 to 7.
8 digits { 0, 1, 2, 3, 4, 5, 6, 7 }



To convert to decimal, you can again use a column weighted system

Weight = (Base)

Position

7512 8 = 7*8 3 + 5*8 2 + 1*8 1 + 2*8 0 = 3914 10


An octal number can easily be converted to binary by replacing each octal
digit with the corresponding group of 3 binary digits
7512 8 = 111101001010 2
Octal Number System


Weights
Weight = (Base)



Position

64

8

1

5 1 2
2

Magnitude

7 4
-1

1

0

Sum of “Digit x Weight”
5 *82+1 *81+2 *80+7 *8-1+4 *8-2

=(330.9375)10


Formal Notation

1/8 1/64

=(512.74)8

-2
Place values for an integer in the octal
system

Real's
Octal Number System
Binary
Decimal
Octal
0

0

0

1

1

1
10
2
2
11
3
3
100
4
4
101
5
Octal is used as a shorthand for representing
5
file permissions on UNIX systems.
110
6
For example, file mode rwxr-xr-x would be 0755.
6
111
7
7
Example
The following shows that the number (1256)8 in octal is the same as 686 in
decimal.

Note that the decimal number is N = 512 + 128 + 40 + 6 = 686.

Example
The weight associated with each digit in the given octal number can be
determined by raising 8 to a power equivalent to the position of the digit in the
number.
Hexadecimal
Number Systems - Hexadecimal


Hexadecimal is a base-16 system.



It contains the digits 0 to 9 and the letters A to F (16 digit values).
16 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F }
Note :- symbols A, B, C, D, E, F are equal to 10, 11, 12, 13, 14 , 15
respectively. The symbols in this system are often referred to as hexadecimal digits



The letters A to F represent the unit values 10 to 15.



This system is often used in programming as a condensed form for binary
numbers (0x00FF, 00FF)



To convert to decimal, use a weighted system with powers of 16.
 Conversion to binary is done the same way as octal to binary
conversions.
 This time though the binary digits are organized into groups of 4.
 Conversion from binary to hexadecimal involves breaking the bits
into groups of 4 and replacing them with the hexadecimal
equivalent.
System


Weights




256

Weight = (Base) Position

Magnitude
 Sum of “Digit x Weight”

1/16 1/256

16

1

1 E

5

7

A

2

0

-1

-2

1

1 *162+14 *161+5 *160+7 *16-1+10 *16-2

=(485.4765625)10


Formal Notation

=(1E5.7A)16
Place values for an integer in the
hexadecimal system
Integers
The Hexadecimal Number System
Binary Decimal
0
0
1
1
10
2
11
3
100
4
101
5
110
6
111
7

Hexadecimal
0
1
2
3
4
5
6
7

Binary Decimal
1000
8
1001
9
1010
10
1011
11
1100
12
1101
13
1110
14
1111
15

Hexadecimal
8
9
A
B
C
D
E
F

Example of a hexadecimal number and the values of the positions
3 C 8 B 0 5 1
166 165 164 163 162 161

160
Hexadecimal System
The weight associated with each symbol in the given hexadecimal number can
be determined by raising 16 to a power equivalent to the position of the digit in
the number.

Example
Digit

4A90.2BC
4

A

9

0

Weight 163 162 161 160

.

2

B

C

Hexadecimal
Point

16-1

16-2

16-3

Example
The following shows that the number (2AE)16 in hexadecimal is equivalent to
686 in decimal.

The equivalent decimal number is N = 512 + 160 + 14 = 686.
Hexadecimal System

Value of 2001 in Binary, Octal and Hexadecimal
Hexadecimal System
Summary of the four positional systems
1).Why do we use the decimal system for
everyday mathematics?
Answer: Fingers and Thumbs
2).Why do we use the binary system for
computer mathematics?
Answer: Computers use voltage levels to
perform mathematics.
0-Volts and 5-Volts correspond to 0’s and 1’s
Common Powers
Base 10
Power

Preface

Symbol

Value

10-12

pico

p

.000000000001

10-9

nano

n

.000000001

10-6

micro

µ

.000001

10-3

milli

m

.001

103

kilo

k

1000

106

mega

M

1000000

109

giga

G

1000000000

1012

tera

T

1000000000000
Common Powers


Base 2
Power

Preface

Symbol

Value

210

kilo

k

1024

220

mega

M

1048576

230

Giga

G

1073741824

• What is the value of “k”, “M”, and “G”?
• In computing, particularly w.r.t. memory,
the base-2 interpretation generally applies
Converting
Numbers
Between
Bases
Conversion Among Bases
The possibilities

Decimal

Octal

Binary

Hexadecimal
Bases






Can represent any quantity in any base
Counting process similar for all bases
 Count until highest digit for base reached
 Add 1 to next higher position to left
 Return to 0 in current position
Conversion: map from one base to another
 Identities easily calculated
 Identities obtained by table lookup
Decimal to Decimal

Decimal

Octal

Binary

Hexadecimal
Example

Weight
12510 =>

5 x 100
2 x 101
1 x 102

Base

=
5
= 20
= 100
125
Decimal to Binary
Decimal

Octal

Binary

Hexadecimal
Converting From Decimal to Binary
• Make a list of the binary place values up to the number being

converted.
• Perform successive divisions by 2, placing the remainder of 0
or 1 in each of the positions from right to left.
• Continue until the quotient is zero.
• Example: 4210

25 24 23 22 21 20
32 16 8 4 2 1
1
0 1 0 1 0
Example

12510 = ?2

2 125
2 62
2 31
2 15
7
2
3
2
1
2
0

1
0
1
1
1
1
1

12510 = 11111012
Example
Decimal to Binary 149210 (decimal) = ???2 (binary)
Repeated Divide by 2
Example
The following shows how to convert 35 in decimal to binary. We start with the
number in decimal, we move to the left while continuously finding the quotients
and the remainder of division by 2. The result is 35 = (100011) 2.

Example
Convert the decimal number 0.625 to binary.

Since the number 0.625 = (0.101)2 has no integral part, the example shows
how the fractional part is calculated.
Decimal (Fraction) to Binary Conversion




Multiply the number by the ‘Base’ (=2)
Take the integer (either 0 or 1) as a coefficient
Take the resultant fraction and repeat the division

Example: (0.625) 10
Integer Fraction

0.625 * 2 =
0.25 * 2 =
0.5 * 2 =
Answer:

Coefficient

a -1 = 1
a -2 = 0
a -3 = 1

1 . 25
0 . 5
1 . 0

(0.625)10 = (0.a-1 a-2 a-3)2 = (0.101)2
MSB

LSB
A similar method can be used to convert a decimal fraction to binary when the
denominator is a power of two:

Exampl
e

The answer is then (0.011011)2
Example
An alternative method for converting a small decimal integer (usually less than
256) to binary is to break the number as the sum of numbers that are
equivalent to the binary place values shown:
Binary to Decimal
Decimal

Octal

Binary

Hexadecimal
Binary to Decimal


Technique






Multiply each bit by 2n, where n is the “weight” of the
bit
The weight is the position of the bit, starting from 0
on the right
Add the results
Decimal
Example

Example
Example

Bit “0”
1010112 =>

1
1
0
1
0
1

x
x
x
x
x
x

20
21
22
23
24
25

=
=
=
=
=
=

1
2
0
8
0
32
4310
Example
The following shows how to convert the binary number
(110.11)2 to decimal: (110.11)2 = 6.75.
Decimal to Octal
Decimal

Octal

Binary

Hexadecimal
Example
123410 = ?8

8
8
8
8

1234
154
19
2
0

2
2
3
2

123410 = 23228
Decimal to Octal Conversion
Example
(175) 10
Quotient Remainder

175 / 8 =
21 / 8 =
2 / 8 =

21 7
2
5
0
2

Answer:

Example
(0.3125) 10

Answer:

a0 = 7
a1 = 5
a2 = 2

(175)10 = (a2 a1 a0)8 = (257)8

Integer Fraction

0.3125 * 8 =
0.5
* 8 =

Coefficient

2 . 5
4 . 0

Coefficient

a -1 = 2
a -2 = 4

(0.3125)10 = (0.a-1 a-2 a-3)8 = (0.24)8
Example
The following shows how to convert 126 in decimal to its equivalent in the octal
system. We move to the right while continuously finding the quotients and the
remainder of division by 8. The result is 126 = (176)8.

Example
The following shows how to convert 0.634 to octal using a maximum of four
digits. The result is 0.634 = (0.5044)8. Note that we multiple by 8 (base octal).
Octal to Decimal
Decimal

Octal

Binary

Hexadecimal
Octal to Decimal


Technique





Multiply each bit by 8 n , where n is the “weight” of the bit
The weight is the position of the bit, starting from 0 on the
right
Add the results

86

85

262144 10 32768 10

84
4096 10

83
512 10

82
64 10

8 10

81
1 10

80
Example
The following shows how to convert (724)8 to decimal.

Example
The following shows how to convert (23.17)8 to decimal.

This means that (23.17)8 ≈ 19.234 in decimal. Again, we have
rounded up 7 × 8−2 = 0.109375.
Decimal to Hexadecimal
Decimal

Octal

Binary

Hexadecimal
Example

123410 = ?16
16
16
16

1234
77
4
0

2
13 = D
4

123410 = 4D216
Example
The following shows how we convert 126 in decimal to its equivalent in the
hexadecimal system. We move to the right while continuously finding the
quotients and the remainder of division by 16. The result is 126 = (7E) 16

Example
The following shows how to convert 178.6 in decimal to hexadecimal using only
one digit to the right of the decimal point. The result is 178.6 = (B2.9) 16 Note
that we divide or multiple by 16 (base hexadecimal).
Hexadecimal to Decimal
Decimal

Octal

Binary

Hexadecimal
Hexadecimal to Decimal


Technique






Multiply each bit by 16n, where n is the “weight” of
the bit
The weight is the position of the bit, starting from 0
on the right
Add the results
16 5

16 0

1048576 10

16 4
65536 10

16 3
4096 10

16 2
256 10

16 10

16 1
1 10
Example
The following shows how
decimal.
ABC16 =>
C x 160
B x 161
A x 162

Example

to convert the hexadecimal number (ABC) 16 to
= 12 x
1 =
12
= 11 x 16 = 176
= 10 x 256 = 2560
274810

The following shows how to convert the hexadecimal number (1A.23) 16 to
decimal.

Note :- The result in the decimal notation is not exact, because
3 × 16−2 = 0.01171875. We have rounded this value to
three
digits (0.012).
Base

N

to Decimal conversion

Decimal to Base

N

Conversions



To convert from decimal to a different number base such as
Octal, Binary or Hexadecimal involves repeated division by that
number base



Keep dividing until the quotient is zero



Use the remainders in reverse order as the digits of the
converted number
Binary to Octal

Decimal

Octal

Binary

Hexadecimal
Binary-octal conversion
8 = 23
Each group of 3 bits represents an octal digit
Group bits in threes, starting on right Convert to octal digits
Binary − Octal Conversion
Example
Octal

1

6

.

2

3

)8

Example
10110101112 = ?8
1 011 010 111
1

3

2

7

010
011
100

5

101

6

( 2

001

2

)2

000

4

( 10110.01

Binary

0

Assume Zeros

110

7

111

10110101112 = 13278
Works both ways (Binary to Octal & Octal to Binary)
Example
What is the binary equivalent of for (24)8?
Solution
Write each octal digit as its equivalent bit pattern to get
2 → 010 and 4 → 100
The result is (010100)2.

Example
Show the octal equivalent of the binary number (101110010) 2.
Solution
Each group of three bits is translated into one octal digit. The equivalent of
each 3-bit group is shown in Table on above page
101
(101110010)2 = (562)8.

110

010
Octal to Binary
Decimal

Octal

Binary

Hexadecimal
Octal to Binary

• Technique
• Convert each octal digit to a 3-bit equivalent binary representation
• Useful to represent binary numbers indirectly
 Octal and binary are nicely related; i.e. 8 = 23
 Each octal digit represent 3 binary digits (bits)
Example
7058 = ?2

7

0

5

111 000 101
7058 = 1110001012
Binary to Hexadecimal

Decimal

Octal

Binary

Hexadecimal
Binary-hexadecimal conversion

Technique
Group bits in fours, starting on right
Convert to hexadecimal digits
Binary − Hexadecimal Conversion



16 = 24
Each group of 4 bits represents a hexadecimal digit

Example:
Assume Zeros

(

1

(

1

0110. 01

6

.

4

)2

)16

Works both ways (Binary to Hex & Hex to Binary)
Example
Show the hexadecimal
(110011100010)2.

equivalent

of

the

binary

number

Solution
We first arrange the binary number in 4-bit patterns:

1100

1110

0010

Note that the leftmost pattern can have one to four bits. We then
use the equivalent of each pattern shown in Table 2.2 on page 25
to change the number to hexadecimal: (4E2)16.
Example
Hexadecimal to Binary
Decimal

Octal

Binary

Hexadecimal
Hexadecimal to Binary




Technique
 Convert each hexadecimal digit to a 4-bit equivalent
binary representation
Useful to represent binary numbers indirectly
 Hex and binary are nicely related; i.e. 16 = 2 4
 Each hex digit represent 4 binary digits (bits)
Example
10AF16 = ?2
1

0

A

F

0001 0000 1010 1111
10AF16 = 00010000101011112
Example
What is the binary equivalent of (24C)16?
Each hexadecimal digit is converted to 4-bit patterns:
2 → 0010, 4 → 0100, and C → 1100
The result is (001001001100)2
Octal to Hexadecimal
Decimal

Octal

Binary

Hexadecimal
Octal-hexadecimal conversion
Conversion


Convert to Binary as an intermediate step

Example

(

(

2

6

.

2

0 01 0110.010 0

Assume Zeros

(

)8

)2
Assume Zeros

1

6

.

4

)16

Works both ways (Octal to Hex & Hex to Octal)
Example

10768 = ?16
1

0

7

6

001

000

111

110

2

3

E

10768 = 23E16
Decimal, Binary, Octal and Hexadecimal
Decimal

Binary

Octal

Hex

00

0000

00

0

01

0001

01

1

02

0010

02

2

03

0011

03

3

04

0100

04

4

05

0101

05

5

06

0110

06

6

07

0111

07

7

08

1000

10

8

09

1001

11

9

10

1010

12

A

11

1011

13

B

12

1100

14

C

13

1101

15

D

14

1110

16

E

15

1111

17

F
Example
Find the minimum number of binary digits required to store
decimal integers with a maximum of six digits.
k = 6, b1 = 10, and b2 = 2. Then
x = [ k × (logb1 / logb2) ] = [6 × (1 / 0.30103)]= 20.

The largest six-digit decimal number is 999,999 and the largest
20-bit binary number is 1,048,575. Note that the largest number
that can be represented by a 19-bit number is 524287, which is
smaller than 999,999. We definitely need twenty bits.
Hexadecimal to Octal
Decimal

Octal

Binary

Hexadecimal
Conversion


Convert to Binary as an intermediate step

Example

(

1

6

.

4

)16

( 0 0 0 1 0 1 1 0 . 01 0 0 )2
Assume Zeros

(

2

6

.

2

)8

Assume Zeros

Works both ways (Octal to Hex & Hex to Octal)
Example

1F0C16 = ?8
1

F

0

C

0001

1111

0000

1100

1

7

4

1

4

1F0C16 = 174148
Exercise – Convert ...
Decimal

Binary

Octal

Hexadecimal

33
1110101
703
1AF
Decimal

Binary

Octal

Hexadecimal

33

100001

41

21

117

1110101

165

75

451

111000011

703

1C3

431

110101111

657

1AF
Common Powers (1 of 2)


Base 10
Power

Preface

Symbol

Value

10-12

pico

p

.000000000001

10-9

nano

n

.000000001

10-6

micro

µ

.000001

10-3

milli

m

.001

103

kilo

k

1000

106

mega

M

1000000

109

giga

G

1000000000

1012

tera

T

1000000000000
Common Powers (2 of 2)


Base 2
Power

Preface

Symbol

Value

210

kilo

k

1024

220

mega

M

1048576

230

Giga

G

1073741824

• What is the value of “k”, “M”, and “G”?
• In computing, particularly w.r.t. memory,
the base-2 interpretation generally applies
Common Powers (2 of 2)
Bits, Bytes, and Words









A bit is a single binary digit (a 1 or 0).
A byte is 8 bits
A word is 32 bits or 4 bytes
Long word = 8 bytes = 64 bits
Quad word = 16 bytes = 128 bits
Programming languages use these standard number
of bits when organizing data storage and access.
What do you call 4 bits?
(hint: it is a small byte)
Binary Calculation
Adding
Subtraction
Multiplying
Division
Decimal Addition

1

1

Carry

5
+
1

5

5

5

1

0
= Ten ≥ Base
Base

 Subtract a
Binary Addition


Column Addition
Carry

1 1 1 1 1 1
1 1 1 1 0 1

= 61

1 0 1 1 1

= 23

1 0 1 0 1 0 0

= 84

+

≥ (2) 10
Binary Addition
Octal Addition

Example

a. 123 8 + 321 8 = ?
123 8
+321 8
444 8

c. 733 8 + 74 8 = ?

b. 4578 + 2458 = ?
4578
+ 2458
7248
Example

Hexadecimal Addition

a. 33 16 + 47 16 = ?
33 16
+ 47 16
7A 16

b. 20D316 + 12BC16 = ?
20D316
+ 12BC16
338F16
Note:- 2410 =1A16

c. DF 16 + AB 16 = ?
d. ADC 16 + DEF 16 = ?
Addition


Question: What is the result of adding 1 to the
largest digit of some number system?

•

(9)10 + 1 = (10)10

•

(7)8 + 1 = (10)8

•

(1)2 + 1 = (10)2

•

(F)16 + 1 = (10)16



Conclusion: Adding 1 to the largest digit in any
number system always has a result of (10) in that
number system.
Binary Subtraction
Borrow a “Base” when needed
Borrow 2 from next line

1
2
0 2 2 0 0 2
1 0 0 1 1 0 1
−

= 77

1 0 1 1 1

= 23

0 1 1 0 1 1 0

= 54

(2= 10) 2
Binary Subtraction
Perform the binary subtraction of the following numbers:
10101 and 01110

A

B

A-B

Borrow

0

0

0

0

0

1

1

1

1

0

1

0

1

1

0

0
Octal Subtraction
a. 524 8 - 167 8 = ?
5

2
4

-

(4)

1
3

1

4

8
(8+4)

(1+8 ) (12)
(9)

6
3

(12)

524 8 - 167 8 = 335 8

7
5

8
8
Octal Subtraction
a. 524 8 - 167 8 = ?
5

2
4

-

1

48

(1+8)

b. 1678 - 248 = ?
(8+4)

(12)

(4) (9) (12)
1
6
78
3

3

c. 1523 8 - 364 8 = ?

524 8 - 167 8 = 335 8

58

167 8
24 8
143 8
Hexadecimal Subtraction
a . 44 16 - 17 16 =?
3

4

(3)
- 1
2

2
44 16 - 17 16 = 2D 16

4 16

(16 + 4) 16

(20) 16
7 16
(13)

D

16

16
Hexadecimal Subtraction
b. 20D316 - 12BC16 = ?

a. 44 16 - 17 16 =?
4
3

(3)
- 1
2

2

4 16

(16 + 4)

(20)
7 16
(13)

D 16

44 16 - 17 16 = 2D 16
c. DF 16 - AB 16 = ?

20D316
- 12BC16
0E1716
Binary Multiplication
Bit by bit
Example

1 0 1 1 1
x

1 0 1 0
0 0 0 0 0
1 0 1 1 1
0 0 0 0 0

1 0 1 1 1
1 1 1 0 0 1 1 0
Binary Multiplication
Example : Perform the binary multiplication of the decimal numbers 12 and 10.
The equivalent binary representation of the decimal number 12 is 1100.
The equivalent binary representation of the decimal number 10 is 1010
Octal Multiplication
Example

25 8 * 16 8 = ?
Method 1

25 8 * 16 8 =446 8
Octal Multiplication
Method 2
Hexadecimal Multiplication
Example

EF * D = ?

EF * D = C23
Hexadecimal Multiplication
2F * 1A =?
Hexadecimal mortification table
Binary Division


•
•

Binary division is also performed in the same way as we perform
decimal division. Like decimal division, we also need to follow the
binary subtraction rules while performing the binary division. The
dividend involved in binary division should be greater than the divisor.
The following are the two important points, which need to be
remembered while performing the binary division.
If the remainder obtained by the division process is greater than or
equal to the divisor, put 1 in the quotient and perform the binary
subtraction.
If the remainder obtained by the division process is less than the
divisor, put 0 in the quotient and append the next most significant
digit from the dividend to the remainder.
Binary Division

Example
The equivalent binary representation of the decimal number 18 is 10010.
The equivalent binary representation of the decimal number 8 is 1000.
Example

Binary Division

Find the quotient and remainder when 1111101 is divided by
1101 in modulo 2 arithmetic.

We find the quotient is 1011, and the remainder is 0010.
This procedure is very useful to us in calculating CRC syndromes
Example

Binary Division
Example

Binary Division
Example

Binary Division
Example

Binary Division
Example

Binary Division
Example

Octal Division

73 8 ÷ 4 8 = ?

73 8 ÷ 4 8 = 16 8 remain 3
Example

Octal Division

17534 8 ÷ 64 8 = ?

64 8 × 2 = 150 8
64 8 × 3 = 234 8
Example

Hexadecimal Division

AB 16 ÷ 3 16 = ?

AB 16 ÷ 3 16 = 39 16

AB 16 ÷ C 16 = ?

AB 16 ÷ C 16 = E.25 16
Example

Hexadecimal Division
DEF 16 ÷ AB 16 = ?
Note :- Short method
AB 16 =10*16 + 11
160+11
171
DE 16 = 13*16 + 14
208 + 14
222
51*16+F=816 + 15 = 831
171*4 = 5C4
171*E = 142E
171*2 = 2E2
Summary of the Division
Bitwise
logic
operations
What is an Operator?








Operator is an operation performed over data at runtime
 Takes one or more arguments (operands)
 Produces a new value
Operators have precedence
 Precedence defines which will be evaluated first
Expressions are sequences of operators and operands that are evaluated to
a single value
Operators can be classified according to
 the type of their operands and of their output

Arithmetic

Relational

Logical

Bitwise
 the number of their operands

Unary (one operand)

Binary (two operands)
Categories of Operators in C#
Category

Operators

Arithmetic + - * / %

++

--

Relational < <= > >= == !=
Logical && ||

^ !

Binary & | ^ ~

<<

>>

Comparison == != < > <= >=
Assignment = += -= *= /= %= &= |= ^= <<= >>=
String concatenation +
Type conversion is as typeof
Other . [] () ?: new
Unary Expression

Binary expression
Relational operators





These perform comparisons and the result is what is called a
boolean: a value TRUE or FALSE
FALSE is represented by 0; anything else is TRUE
The relational operators are:







<
<=
>
>=
==
!=

(less than)
(less than or equal to)
(greater than)
(greater than or equal to)
(equal to)
(not equal to)
Logical Operators

(also called Boolean

operators)



These have Boolean operands and the result is also a Boolean.
The basic Boolean operators are:
&& (logical AND)




||

(logical OR)

! (logical NOT) -- unary

Operator ! turns true to false and false to true
Behavior of the operators &&, || and ^ (1 == true, 0 == false)

Example :bool a = true;
bool b = false;

(a && b)

False

(a || b)

True

(a ^ b)

True

(!b)

True

(b || true)

True

(b && true)

False

(a || true)

True

(a && true)

True

(!a)

False

((5>7) ^ (a==b))

False
Logical Operators
operators)

(also called Boolean
Logical Operators
(also called Boolean operators)

Operation

&&

&&

&&

&&

Operand1

0

0

1

1

Operand2

0

1

0

1

Result

0

0

0

1

Operation

^

^

^

^

Operand1

0

0

1

1

Operand2

0

1

0

1

Result

0

1

1

0

Operation

||

||

||

||

Operand1

0

0

1

1

Operand2

0

1

0

1

Result

0

1

1

1
BITWISE OPERATORS

Bitwise operators operate on individual bits of integer (int and long) values.
If an operand is shorter than an int, it is promoted to int before doing the
operations.
Negative integers are store in two's complement form. For example, -4 is 1111
1111 1111 1111 1111 1111 1111 1100.
Bitwise operator ~ turns all 0 to 1 and all 1 to 0
expressions but bit by bit

Like ! for boolean

The operators |, & and ^ behave like ||, && and ^ for Boolean expressions
but bit by bit
The << and >> move the bits (left or right)
Bitwise operators are used on integer numbers

(byte, sbyte, int, uint, long, ulong)

Bitwise operators are applied bit by bit
Bitwise Operator
Operator

Value

~

Bitwise unary NOT

&

Bitwise AND

|

Bitwise OR

^

Bitwise XOR

>>
>>>

Shift Right
Shift Right zero fill

<<

Shift left

& =

Bitwise AND Assignment

|=

Bitwise OR Assignment

^=

Bitwise XOR Assignment

>>=
>>>=
<<=

Shift Right Assignment
Shift Right zero fill Assignment
Shift Left Assignment
Bitwise Operator
{ NOT A } as

∼A

{ A AND B } as
A AND B=A × B
A &
B=A ×
B

A

∼A

0

1

1

NOT A =

0

A

B

A×B

0

0

0

0

1

0

1

0

0

1

1

1
Bitwise Operator
{ A OR B } as follows
A OR B=A+B
A | B=A+B

A

B

A+B

{ A OR B OR C} as
follows
A OR B OR C =A+B+C
A |
B
| C= A+B+C

A

B

C

A+B+C

0

0

0

0

0

0

1

1

0

0

0

0

1

1

0

1

0

1

0

1

1

1

1

0

1

1

0

0

1

1

0

1

1

1

1

0

1

1

1

1

1

1

1

1
Bitwise Operator
{ A XOR B } as
A XOR B = (∼A)B + A(∼B)
A ^
B = ( ∼A)B + A(∼B)

B

A⊗B

0

0

0

0

1

1

1

0

1

1
Summary

A

1

0
BITWISE OPERATORS
Ope ration

|

|

|

|

&

&

&

&

^

^

^

^

Ope rand1

0

0

1

1

0

0

1

1

0

0

1

1

Ope rand2

0

1

0

1

0

1

0

1

0

1

0

1

Re s ult

0

1

1

1

0

0

0

1

0

1

1

0

Examples:

a = 3; is 00000011
b = 5; is 00000101
( a | b); // 00000111
( a & b); // 00000001
( a ^ b); // 00000110
(~a & b); // 00000100
( a<<1 ); // 00000110
( a>>1 ); // 00000001
Bitwise Operator
Bitwise Operator
Bitwise Operator
Bitwise Operator
<-------Bitwise Logical Operators------->
Example :- The binary value of a = 0010 and b = 0111
1.The Bitwise OR : a | b = 7
2.The Bitwise AND : a & b = 2
3.The Bitwise XOR(exclusive OR) : a ^ b = 5
4.The Bitwise unary NOT : ~a & a = 0
5.~a&b|a&~b = 5

<-------Bitewise Shift Operators------->
Example :- The original binary value of a = 0010 and Decimal value of a = 2

1.The Left shift : a = 8
2. The Right shift : b = b >> 2 = 1
3.The original decimal value of u = -1
4. The Unsigned Right shift : u = u >>> 30 means u = 11111111 11111111 11111111
11111111 >>> 30 hence u = 0011 and Decimal value of u = 3

<-------Bitewise Assignment Operators------->
Example :- The original binary value of p = 0101 and Decimal value of p = 5
1.The Bitewise Shift Right Assignment Operators : p >>= 2 means p = p >>
hence p =0101 >> 2 so p = 0001 and Decimal value of p = 1
Bitwise Operator

Bitwise operators are used in

1.Communication stacks where the individual bits in the header attached to the
data signify important information
2.Embedded software for controlling different functions in the chip and
indicating the status of hardware by manipulating the individual bits of
hardware registers of embedded microcontrollers
3.Low-level programming for applications such as device drivers, cryptographic
software, video decoding software, memory allocators, compression software
and graphics
4.Maintaining large sets of integers efficiently in search and optimization
problems
5.Bitwise operations performed on bit flags, which can enable an instance of
enumeration type to store any combination of values defined in an enumerator
list
Low level languages are:
1 - Machine Language
2 - Assembly Language
3 - C (C is not the 100% Low-level language)

High level languages are:
1 - Visual Basic
2 - Pascal
3 - Java
4 - C++
and many more.

Weitere ähnliche Inhalte

Was ist angesagt?

Number system....
Number system....Number system....
Number system....
mshoaib15
 
Number system
Number systemNumber system
Number system
kashee99
 
Number System
Number SystemNumber System
Number System
itutor
 

Was ist angesagt? (20)

Number System and Boolean Algebra
Number System and Boolean AlgebraNumber System and Boolean Algebra
Number System and Boolean Algebra
 
Binary to decimal Conversion
Binary to decimal ConversionBinary to decimal Conversion
Binary to decimal Conversion
 
Number system
Number systemNumber system
Number system
 
Binaty Arithmetic and Binary coding schemes
Binaty Arithmetic and Binary coding schemesBinaty Arithmetic and Binary coding schemes
Binaty Arithmetic and Binary coding schemes
 
Binary codes
Binary codesBinary codes
Binary codes
 
Binary Arithmetic
Binary ArithmeticBinary Arithmetic
Binary Arithmetic
 
Number System
Number SystemNumber System
Number System
 
Number system....
Number system....Number system....
Number system....
 
Number system
Number systemNumber system
Number system
 
Binary true ppt
Binary true pptBinary true ppt
Binary true ppt
 
Number System
Number SystemNumber System
Number System
 
Number system
Number systemNumber system
Number system
 
Number system and codes
Number system and codesNumber system and codes
Number system and codes
 
Binary operations
 Binary operations Binary operations
Binary operations
 
Number systems ppt
Number systems pptNumber systems ppt
Number systems ppt
 
11 octal number system
11   octal number system11   octal number system
11 octal number system
 
Floating point representation
Floating point representationFloating point representation
Floating point representation
 
Number System
Number SystemNumber System
Number System
 
Number system conversion
Number system conversionNumber system conversion
Number system conversion
 
Number System
Number SystemNumber System
Number System
 

Andere mochten auch

Introduction to the Binary Number System
Introduction to the Binary Number SystemIntroduction to the Binary Number System
Introduction to the Binary Number System
James Hamilton
 
Creación de una Planta para el Mantenimiento y Procesamiento del Agua - Inici...
Creación de una Planta para el Mantenimiento y Procesamiento del Agua - Inici...Creación de una Planta para el Mantenimiento y Procesamiento del Agua - Inici...
Creación de una Planta para el Mantenimiento y Procesamiento del Agua - Inici...
David Salomon Rojas Llaullipoma
 
Redes Sociales para PyMes
Redes Sociales para PyMesRedes Sociales para PyMes
Redes Sociales para PyMes
Carmen Tipacti
 
Comercio electrónico en méxico
Comercio electrónico en méxicoComercio electrónico en méxico
Comercio electrónico en méxico
Omar Sánchez
 

Andere mochten auch (20)

Number System
Number SystemNumber System
Number System
 
number system school ppt ninth class
number system school ppt ninth classnumber system school ppt ninth class
number system school ppt ninth class
 
Introduction to the Binary Number System
Introduction to the Binary Number SystemIntroduction to the Binary Number System
Introduction to the Binary Number System
 
Number system
Number systemNumber system
Number system
 
La estructura de revoluciones cientificas
La estructura de revoluciones cientificasLa estructura de revoluciones cientificas
La estructura de revoluciones cientificas
 
365 afval tips
365 afval tips365 afval tips
365 afval tips
 
Componentes principales act
Componentes principales actComponentes principales act
Componentes principales act
 
Trabajo en equipo cristina rodriguez guerra aplicaciones web 2.0 anpe jaen
Trabajo en equipo cristina rodriguez guerra aplicaciones web 2.0 anpe jaenTrabajo en equipo cristina rodriguez guerra aplicaciones web 2.0 anpe jaen
Trabajo en equipo cristina rodriguez guerra aplicaciones web 2.0 anpe jaen
 
MOOCS and the Future of Higher Education
MOOCS and the Future of Higher EducationMOOCS and the Future of Higher Education
MOOCS and the Future of Higher Education
 
Comprendiendo el entorno 1
Comprendiendo el entorno   1Comprendiendo el entorno   1
Comprendiendo el entorno 1
 
Innovación paso a paso
Innovación paso a pasoInnovación paso a paso
Innovación paso a paso
 
Southern Fried Trolling: The Art Of Bless Your Heart
Southern Fried Trolling: The Art Of Bless Your HeartSouthern Fried Trolling: The Art Of Bless Your Heart
Southern Fried Trolling: The Art Of Bless Your Heart
 
Karl marx
Karl marxKarl marx
Karl marx
 
Creación de una Planta para el Mantenimiento y Procesamiento del Agua - Inici...
Creación de una Planta para el Mantenimiento y Procesamiento del Agua - Inici...Creación de una Planta para el Mantenimiento y Procesamiento del Agua - Inici...
Creación de una Planta para el Mantenimiento y Procesamiento del Agua - Inici...
 
Redes Sociales para PyMes
Redes Sociales para PyMesRedes Sociales para PyMes
Redes Sociales para PyMes
 
Beautiful Web Typography (#5)
Beautiful Web Typography (#5)Beautiful Web Typography (#5)
Beautiful Web Typography (#5)
 
Ucd火花集
Ucd火花集Ucd火花集
Ucd火花集
 
Ananananaan
AnanananaanAnanananaan
Ananananaan
 
Comercio electrónico en méxico
Comercio electrónico en méxicoComercio electrónico en méxico
Comercio electrónico en méxico
 
Ucd火花集
Ucd火花集Ucd火花集
Ucd火花集
 

Ähnlich wie Number system part 1

Data storage & representation
Data storage & representationData storage & representation
Data storage & representation
minealone
 
Lesson 1 basic theory of information
Lesson 1   basic theory of informationLesson 1   basic theory of information
Lesson 1 basic theory of information
Roma Kimberly Erolin
 
Lesson 1 basic theory of information
Lesson 1   basic theory of informationLesson 1   basic theory of information
Lesson 1 basic theory of information
Roma Kimberly Erolin
 

Ähnlich wie Number system part 1 (20)

Number system.pdf
Number system.pdfNumber system.pdf
Number system.pdf
 
decimals-comp-packet.pdf
decimals-comp-packet.pdfdecimals-comp-packet.pdf
decimals-comp-packet.pdf
 
Data repersentation.
Data repersentation.Data repersentation.
Data repersentation.
 
NUMBER SYSTEM.pptx
NUMBER SYSTEM.pptxNUMBER SYSTEM.pptx
NUMBER SYSTEM.pptx
 
Number – place value
Number – place valueNumber – place value
Number – place value
 
Number+system (1)
Number+system (1)Number+system (1)
Number+system (1)
 
Chap1_Number and Number Sydtem.pptx
Chap1_Number and Number Sydtem.pptxChap1_Number and Number Sydtem.pptx
Chap1_Number and Number Sydtem.pptx
 
SD & D Real Numbers
SD & D Real NumbersSD & D Real Numbers
SD & D Real Numbers
 
Secondary Lecture
Secondary LectureSecondary Lecture
Secondary Lecture
 
NUMBER SYSTEM.pptx
NUMBER  SYSTEM.pptxNUMBER  SYSTEM.pptx
NUMBER SYSTEM.pptx
 
Number system computer fundamental
 Number  system computer fundamental  Number  system computer fundamental
Number system computer fundamental
 
Maths number system
Maths   number systemMaths   number system
Maths number system
 
Data storage & representation
Data storage & representationData storage & representation
Data storage & representation
 
Lesson 1 basic theory of information
Lesson 1   basic theory of informationLesson 1   basic theory of information
Lesson 1 basic theory of information
 
Lesson 1 basic theory of information
Lesson 1   basic theory of informationLesson 1   basic theory of information
Lesson 1 basic theory of information
 
Number System
Number SystemNumber System
Number System
 
Motivation
MotivationMotivation
Motivation
 
Decimal numbers 1º eso
Decimal numbers 1º esoDecimal numbers 1º eso
Decimal numbers 1º eso
 
1.Digital Electronics overview & Number Systems.pptx
1.Digital Electronics overview & Number Systems.pptx1.Digital Electronics overview & Number Systems.pptx
1.Digital Electronics overview & Number Systems.pptx
 
FYBSC IT Digital Electronics Unit I Chapter I Number System and Binary Arithm...
FYBSC IT Digital Electronics Unit I Chapter I Number System and Binary Arithm...FYBSC IT Digital Electronics Unit I Chapter I Number System and Binary Arithm...
FYBSC IT Digital Electronics Unit I Chapter I Number System and Binary Arithm...
 

Kürzlich hochgeladen

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Kürzlich hochgeladen (20)

Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 

Number system part 1

  • 2. Objectives - To understand 3.1 Analyses how numeric data are represented in computers I. II. III. IV. V. Decimal representation of numbers (Signed and Unsigned) Integers Fixed Point and Floating-Point numbers Number systems used in computing Binary, Octal, Hexa-decimal logic operation Conversions among number systems
  • 4. Introductio n A number system defines a set of values used to represent a quantity. The study of numbers is not only related to computers. We apply numbers everyday, and knowing how numbers work, will give us an insight of how computers manipulate and store numbers. A number is a mathematical object used in counting and measuring. It is used in counting and measuring. Numerals are often used for labels, for ordering serial numbers, and for codes like ISBNs. In mathematics, the definition of number has been extended over the years to include such numbers as zero, Positive numbers , Negative numbers , Integers numbers , Rational numbers, Irrational numbers, Whole number and complex numbers. Certain procedures which take one or more numbers as input and produce a number as output are called numerical operation.
  • 5. Types of numbers Complex number:- The complex numbers consist of all numbers of the form (a+bi) ; Where a and b are real numbers and i=0.1 Ex :- 2+5i , 3+3i , … . .. . . . , 14+20i Real Numbers (R) :- The real numbers include all of the measuring numbers Ex :- -69 , -2 , -1.5 , +5 …+ 7.5 . .. . . . , +14 Rational Numbers (Q) :- A rational number is a number that can be expressed as a fraction with an integer and a non-zero natural number denominator Ex :- -25 , -15/10 , 0 , 0.05 , 0.2 , 7/3 , 25 ,36 Irrational Numbers:- A decimal that can be written as a fraction either ends (terminates)or forever repeats about which we will see in detail further. Ex – π =3.14159365358979 Natural numbers (N) :- All positive numbers (Counting numbers) started with 1.However in the 19th century, mathematicians started including 0 in the set of natural numbers. Ex :- 0,1,2,3,4,……,55 ,105 . .. . . .
  • 6. Types of numbers Integers (Z):- Integers are the number which includes positive and negative numbers. Negative numbers are usually written with a negative sign (also called a minus sign)in front of the number they are opposite of .When the set of negative numbers is combined with the natural numbers zero, the result is the set of integer numbers Ex :- -25 , -15 , +0 , +25 , +36 Fractions :- This is a type of a rational number. Fractions are written as two numbers (m/n), the numerator (m) and the denominator(n) 1. Fixed point Number 2.Floating point number
  • 7. Fixed point number :- Involving or being a mathematical notation(as in a decimal system) in which the point separating whole numbers and fractions is fixed A fixed point number has a specific number of bits (or digits) reserved for the integer part (the part to the left of the decimal point) and a specific number of bits reserved for the fractional part (the part tothe right of the decimal point). No matter how large or small your number is, it will always use the same number of bits for each portion. For example:- if your fixed point format was in decimal IIIII.FFFFF then the largest number you could represent would be 99999.99999 and the smallest would be 00000.00001. Every bit of code that processes such numbers has to have built-in knowledge of where the decimal point is. 123.56 25.23 8955.3 0.5 0.0098 A fixed point number just means that there are a fixed number of digits after the decimal point.
  • 8. Floating point number :A floating point number does not reserve a specific number of bits for the integer part or the fractional part. Instead it reserves a certain number of bits for the number (called the mantissa or significant ) and a certain number of bits to say where within that number the decimal place sits (called the exponent). For example:-So a floating point number that took up 10 digits with 2 digits reserved for the exponent might represent a largest value of 9.9999999e+50 and a smallest value of 0.0000001e-49. 1.2 × 10 2 35.02 × 10 80 0.258 × 10 -14 / 2.58 × 10 -15 / 25.8 × 10 -16 A floating point number allows for a varying number of digits after the decimal point.
  • 10.
  • 11. Precision({Í ý<) and Accuracy (ùÚØ<÷À]õ$< •Precision is the measure of how closely individual measurements agree with one another. • Accuracy is how closely individual measurements with the correct value.
  • 12.
  • 13. Significant Digits( µ<µ&&Ú &‘ç]$‘æ×) "Significant Digits", also called "Significant Digits of Precision ", are the digits in a number starting with the first non-zero digit and ending with the last non-zero digit. Those digits can be anywhere relative to the decimal. Non-zero digits are always significant. 22 has two significant digits, 22.3 has three significant digits. With zeroes, the situation is more complicated a. Zeroes placed before other digits are not significant; 0.046 has two significant digits. b. Zeroes placed between other digits are always significant; 4009 kg has four significant digits. c. Zeroes placed after other digits but behind a decimal point are significant; 7.90 has three significant digits. 85.00 g has four significant digits 9.000 000 000 mm has 10 significant digits
  • 14. Significant Digits d. Zeros at the end of a number but to the left of a decimal may or may not be significant. If such a zero has been measured, or is the first estimated digit, it is significant. On the other hand, if the zero has not been measured or estimated but is just a placeholder, it is not significant. A decimal placed after the zeros indicates that they are significant 1. 2000 m may contain from one to fou r significant digits, depending on how many zeros are placeholders. For measurements given in this text , assume that 2000 has one significant digits. 2. 2000 . m contains four significant digits, indicated by the presence of the decimal point 3.1000.0 has five significant digits (the ".0" tells us something interesting about the presumed accuracy of the measurement being made: that the measurement is accurate to the tenths place, but that there happen to be zero tenths) For example:- in the number 8200, it is not clear if the zeroes are significant or not. The number of significant digits in 8200 is at least two, but could be three or four. To avoid uncertainty, use scientific notation to place significant zeroes behind a decimal point: i.8.200 *103 has four significant digits ii.8.20 *103 has three significant digits iii.8.2 *103 has two significant digits
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22. Significant Digits Scientific notation - All digits expressed before the exponential term are significant. 5.060 x 10-3 m has four sig figs. 9.00 x 102 g has three sig figs.
  • 23. Most Significant Digit Significant Digit •The MSD in a number is the digit that has the greatest effect on that number. Highest power of base weighting The digits on the left hand side are called the high-order digits (higher powers of 10) Least Significant Digit (MSD and LSD) • The LSD in a number is the digit that has the least effect on that number. • Lowest power of base weighting • Digits on the right hand side are called the low-order digits (lower powers of 10).
  • 24. Significant Digit You can easily see that a change in the MSD will increase or decrease the value of the number the greatest amount. Changes in the LSD will have the smallest effect on the value. The nonzero digit of a number that is the farthest LEFT is the MSD, and the nonzero digit farthest RIGHT is the LSD, as in the following example
  • 25. Key principle of numbering systems Radix point (´ÕÙæ ÙæßÂ]× ) Divides fractional portion from the whole portion of a number Weighting Factor ( ýØ &$øæ× ) A multiplier value is used in each column position of a number . It represents the weight factor. Its value determines how many times the Base value is multiplied by itself thus giving the placeholders seen below from right to left labelled as "Ones", "Tens", "Hundreds", "Thousands", "Ten Thousands" and so on. . .
  • 26. OSITIONAL (&ßö$ùÛ×)NUMBER SYSTEMS In a positional number system, the position a symbol occupies in the number determines the value it represents. In this system, a number represented as: In our decimal number system, the value of a digit depends on its place, or position, in the number. Each place has a value of 10 times the place to its right. A number in standard form is separated into groups of three digits using commas. Each of these groups is called a period.
  • 29. OSITIONAL (&ßö$ùÛ×)NUMBER SYSTEMS In a positional number system, the position a symbol occupies in the number determines the value it represents. In this system, a number represented as: has the value of: in which S is the set of symbols, b is the base (or radix).
  • 30. Key principle of numbering systems Positional value significance Gives weight each digit contributes to the number’s overall value Ex:-1.Steps for base 10 Determine positional value of each digit by raising 10 to position within number 2. Steps for base 2 Determine positional value of each digit by raising 2 to position within number
  • 31. Calculate Position Value and Weighed General procedure (any base)  Calculate position value of the number by raising the base value to the power of the position  Multiply positional value by digit in that position  Add each calculated value together
  • 32. Number Representations Integer numbers are those numbers which do not have fractional parts. Integer numbers include both positive numbers and negative numbers. They can be handled using any of the following representations Unsigned notation Signed magnitude notion 
  • 33. Unsigned notation An unsigned integer is an integer that can never be negative and can take only 0 or positive values. Its range is between 0 and positive infinity. All unsigned numbers are Positive 0 , 1 , 2 , 3 , 4 , . . . . , 1598 , . . . . Range = 0 to (2n – 1) ; n is the number of bits used to store the unsigned integer. Numbers with values GREATER than (2n – 1) would require more bits. If you try to store too large a value without using more bits, OVERFLOW will occur. Example: On a system that stores unsigned integers in 16-bit words: Range = 0 to (216 – 1) = 0 to 65535 Therefore, you cannot store numbers larger than 65535 in 16 bits.
  • 34. Unsigned representation Advantages: 1.One representation of zero 2.Simple addition Disadvantages : 1.Negative numbers can not be represented. 2.The need of different notation to represent negative numbers.
  • 35. Signed notation  Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers (like : -12, -45, +78).  A signed number MUST have a sign (+/-). A method is needed to represent the sign as part of the binary representation. All signed numbers are negative and positive -1.5× 103 , - 25 , -9.6×10-4 , +0 , +5.7×10-4 , +0.5 , +98 , +4.6 ×103 Range =-(2(n-1) – 1) to +(2(n-1) – 1) ; n is the number of bits used to store the sign/magnitude integer Numbers with values GREATER than +(2(n-1) – 1) and values LESS than -(2(n-1) – 1) would require more bits. If you try to store too large/too small a value without using more bits, OVERFLOW will occur. Example: On a system that stores unsigned integers in 16-bit words: Range = -(2(16-1) – 1) to +(2(16-1) – 1) = -(2(15) – 1) to +(2(15) – 1) = -32767 to +32767 Therefore, you cannot store numbers larger than 32767 or smaller than -32767 in 16 bits.
  • 36. Sign Representation Advantages: Represents positive and negative numbers Disadvantage :  Arithmetic operations are difficult. Addition and subtractions are difficult. Signs and magnitude, both have to carry out the required operation. They are two representations of 0 (Binary number system) 00000000 = + 010 10000000 = - 010 To test if a number is 0 or not, the CPU will need to see whether it is 00000000 or 10000000. 0 is always performed in programs. Therefore, having two representations of 0 is inconvenient.
  • 39. Numbering Systems  Integer ……………. Z Decimal…………… Base 10 (N10 )  Binary …………….. Base 2 (N2 )  Octal ………………. Base 8 (N8 )  Hexadecimal ……. Base 16 
  • 41. Integer A number with no fractional part Includes the counting numbers {1, 2, 3, ...}, zero {0}, and the negative of the counting numbers {-1, -2, -3, ...} You can write them down like this: {..., -3, -2, -1, 0, 1, 2, 3, ...} Examples of integers: -16, -3, 0, 1, 198
  • 43. Decimal Number System   The decimal system is a base-10 system. There are 10 distinct digits (0 to 9) to represent any quantity. 10 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }   For an n-digit number, the value that each digit represents depends on its weight or position. Digit Position Integer & fraction 123.456  The weights are based on powers of 10. Weight = (Base) Position 1024 = 1*103 + 0*102 + 2*101 + 4*100 = 1000 + 20 + 4 Positional value example: 436.95 To the left of the radix point : 4 in position two / 3 in position one / 6 in position zero To the right of the radix point: 9 in position negative one / 5 in position negative two
  • 44. Decimal Number System  Base (also called radix) = 10   Digit Position   Integer & fraction Weight = (Base) 0 -1 -2 7 4 10 1 0.1 0.01 10 2 0.7 0.04 Position Sum of “Digit x Weight” Formal Notation 1 5 1 2 100 Magnitude   2 Digit Weight   10 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } 500 d2*B2+d1*B1+d0*B0+d-1*B-1+d-2*B-2 (512.74)10
  • 45. Example For D = 52.946
  • 46. Standard decimal representation Uses the ten numbers from 0 to 9 Each column represents a power of 10 Fixed-point representation Uses the two numbers from 0 to 9 Every column represents a power of 10
  • 47. Positional Value (cont’d.) Positional values for a base 10 number
  • 48. Whole Numbers (Radix = 10): 123410 = 1 × 103 + 2 × 102 + 3 × 101 + 4 × 100 With Fractional Part (Radix = 10): 36.7210 = 3 × 101 + 6 × 100 + 7 × 10-1 + 2 × 10-2 General Case (Radix = R): (S1S0.S-1S-2)R = S1 × R1 + S0 × R0 + S-1 × R -1 + S-2 × R-2 Reals
  • 49. Practice (base 10) 1) 258 = 2.58 x 10 2 Mantissa = 258 Radix = 10 Exponent = 2 3) One billion =1,000,000,000 =1 x 109    significand or mantissa: 1 base or radix: 10 exponent: 9 (Scientific notation ) 4) 1999 =1.999 x 103 significand or mantissa: 1999 base or radix: 10 exponent: 3 =19.99 x 102 =199.9 x 101 2) 24.25 = 2.425 x 10 1 =Mantissa = 2425 =Radix = 10 =Exponent = 1 2) The following shows the place values for the integer +224 in the decimal system. Note that the digit 2 in position 1 has the value 20, but the same digit in position 2 has the value 200. Also note that we normally drop the plus sign, but it is implicit.
  • 50. Example The following shows the place values for the decimal number −7508. We have used 1, 10, 100, and 1000 instead of powers of 10. ( ) Values Note that the digit 2 in position 1 has the value 20, but the same digit in position 2 has the value 200. Also note that we normally drop the plus sign, but it is implicit. Example The following shows the place values for the real number +24.13.
  • 52. Binary Number Systems  The binary system is a base-2 system.  There are 2 distinct digits (0 and 1) to represent any quantity. 2 digits { 0, 1 }, called binary digits or “bits” • 0 = represents no value • 1 = represents a unit value  For an n-digit number, the value of a digit in each column depends on its position.  The weights are based on powers of 2. Weight = (Base) Position 1011 2 = 1*2 3 + 0*2 2 + 1*2 1 + 1*2 0 =8+2+1 =11 10
  • 53. Binary Number System  Weights 4 Weight = (Base) Position  Magnitude  Formal Notation Groups of bits 1 1/2 1/4 1 0 1 0 1 2 -1 -2 1 0 =1 *2 2 +0 *2 1 +1 *2 0 +0 *2 -1 +1 *2 -2 Sum of “Bit x Weight”  2 =(5.25) 10 =(101.01)2 4 bits = Nibble 8 bits = Byte 1011 11000101
  • 54. Binary Number System Binary number Value encoded by the binary number 0 0×2 0 = 0 1 1×2 0 = 1 10 1×2 1 + 0 ×2 0 = 2 11 1×2 1 + 1 ×2 0 = 3 1010 1×2 3 + 0×22 + 1×21 + 0×20 = 8 + 2 = 10 Base-2 scientific notation 1) 2.25ten = 10.01two = 10.01two x 20 = 1.001two x 21  normalized Numbers are usually normalized which means that the leading bit is always a 1. 2) 1100.101two Digit 1 1 0 0 . 1 0 1 Weight 23 22 21 20 Binary decimal Point 2-1 2-2 2-3
  • 55. Standard binary representation Uses the two numbers from 0 to 1 Every column represents a power of 2 Fixed-point representation Uses the two numbers from 0 to 1 Every column represents a power of 2
  • 56. Positional Value 1)Positional value of the binary number 10112 Rightmost position: positional value of the base (2) raised to the 0 power First Positional value: 1 (1 * 20) Next position: value of 2 raised to the power of 1 (1 * 21) Next position: 2 squared (0 * 22) Next position: 2 to the third (1 * 23) (1 * 20) + (1 * 21) + (0 * 22) + (1 * 23) 2)Positional value of the binary number 1011.0112 as follows
  • 57.
  • 58. Whole Numbers (Radix = 2): 10112 = 1 × 23 + 0 × 22 + 1 × 21 + 1 × 20 With Fractional Part (Radix = 2): 11.012 = 1 × 21 + 1 × 20 + 0 × 2-1 + 1 × 2-2 General Case (Radix = R): (S1S0.S-1S-2)R = S1 × R1 + S0 × R0 + S-1 × R -1 + S-2 × R-2 Real's
  • 59. Example The following shows that the number (11001)2 in binary is the same as 25 in decimal. The subscript 2 shows that the base is 2. The equivalent decimal number is N = 16 + 8 + 0 + 0 + 1 = 25. Example The following shows that the number (101.11)2 in binary is equal to the number 5.75 in decimal.
  • 60. Octal
  • 61. Octal Number Systems  Octal and hexadecimal systems provide a shorthand way to deal with the long strings of 1’s and 0’s in binary.  Octal is base-8 system using the digits 0 to 7. 8 digits { 0, 1, 2, 3, 4, 5, 6, 7 }  To convert to decimal, you can again use a column weighted system Weight = (Base) Position 7512 8 = 7*8 3 + 5*8 2 + 1*8 1 + 2*8 0 = 3914 10  An octal number can easily be converted to binary by replacing each octal digit with the corresponding group of 3 binary digits 7512 8 = 111101001010 2
  • 62. Octal Number System  Weights Weight = (Base)  Position 64 8 1 5 1 2 2 Magnitude 7 4 -1 1 0 Sum of “Digit x Weight” 5 *82+1 *81+2 *80+7 *8-1+4 *8-2 =(330.9375)10  Formal Notation 1/8 1/64 =(512.74)8 -2
  • 63. Place values for an integer in the octal system Real's
  • 64. Octal Number System Binary Decimal Octal 0 0 0 1 1 1 10 2 2 11 3 3 100 4 4 101 5 Octal is used as a shorthand for representing 5 file permissions on UNIX systems. 110 6 For example, file mode rwxr-xr-x would be 0755. 6 111 7 7
  • 65. Example The following shows that the number (1256)8 in octal is the same as 686 in decimal. Note that the decimal number is N = 512 + 128 + 40 + 6 = 686. Example The weight associated with each digit in the given octal number can be determined by raising 8 to a power equivalent to the position of the digit in the number.
  • 67. Number Systems - Hexadecimal  Hexadecimal is a base-16 system.  It contains the digits 0 to 9 and the letters A to F (16 digit values). 16 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F } Note :- symbols A, B, C, D, E, F are equal to 10, 11, 12, 13, 14 , 15 respectively. The symbols in this system are often referred to as hexadecimal digits  The letters A to F represent the unit values 10 to 15.  This system is often used in programming as a condensed form for binary numbers (0x00FF, 00FF)  To convert to decimal, use a weighted system with powers of 16.  Conversion to binary is done the same way as octal to binary conversions.  This time though the binary digits are organized into groups of 4.  Conversion from binary to hexadecimal involves breaking the bits into groups of 4 and replacing them with the hexadecimal equivalent.
  • 68. System  Weights   256 Weight = (Base) Position Magnitude  Sum of “Digit x Weight” 1/16 1/256 16 1 1 E 5 7 A 2 0 -1 -2 1 1 *162+14 *161+5 *160+7 *16-1+10 *16-2 =(485.4765625)10  Formal Notation =(1E5.7A)16
  • 69. Place values for an integer in the hexadecimal system Integers
  • 70. The Hexadecimal Number System Binary Decimal 0 0 1 1 10 2 11 3 100 4 101 5 110 6 111 7 Hexadecimal 0 1 2 3 4 5 6 7 Binary Decimal 1000 8 1001 9 1010 10 1011 11 1100 12 1101 13 1110 14 1111 15 Hexadecimal 8 9 A B C D E F Example of a hexadecimal number and the values of the positions 3 C 8 B 0 5 1 166 165 164 163 162 161 160
  • 71. Hexadecimal System The weight associated with each symbol in the given hexadecimal number can be determined by raising 16 to a power equivalent to the position of the digit in the number. Example Digit 4A90.2BC 4 A 9 0 Weight 163 162 161 160 . 2 B C Hexadecimal Point 16-1 16-2 16-3 Example The following shows that the number (2AE)16 in hexadecimal is equivalent to 686 in decimal. The equivalent decimal number is N = 512 + 160 + 14 = 686.
  • 72. Hexadecimal System Value of 2001 in Binary, Octal and Hexadecimal
  • 74. Summary of the four positional systems
  • 75. 1).Why do we use the decimal system for everyday mathematics? Answer: Fingers and Thumbs 2).Why do we use the binary system for computer mathematics? Answer: Computers use voltage levels to perform mathematics. 0-Volts and 5-Volts correspond to 0’s and 1’s
  • 77. Common Powers  Base 2 Power Preface Symbol Value 210 kilo k 1024 220 mega M 1048576 230 Giga G 1073741824 • What is the value of “k”, “M”, and “G”? • In computing, particularly w.r.t. memory, the base-2 interpretation generally applies
  • 79. Conversion Among Bases The possibilities Decimal Octal Binary Hexadecimal
  • 80. Bases    Can represent any quantity in any base Counting process similar for all bases  Count until highest digit for base reached  Add 1 to next higher position to left  Return to 0 in current position Conversion: map from one base to another  Identities easily calculated  Identities obtained by table lookup
  • 82. Example Weight 12510 => 5 x 100 2 x 101 1 x 102 Base = 5 = 20 = 100 125
  • 84. Converting From Decimal to Binary • Make a list of the binary place values up to the number being converted. • Perform successive divisions by 2, placing the remainder of 0 or 1 in each of the positions from right to left. • Continue until the quotient is zero. • Example: 4210 25 24 23 22 21 20 32 16 8 4 2 1 1 0 1 0 1 0
  • 85. Example 12510 = ?2 2 125 2 62 2 31 2 15 7 2 3 2 1 2 0 1 0 1 1 1 1 1 12510 = 11111012
  • 86. Example Decimal to Binary 149210 (decimal) = ???2 (binary) Repeated Divide by 2
  • 87. Example The following shows how to convert 35 in decimal to binary. We start with the number in decimal, we move to the left while continuously finding the quotients and the remainder of division by 2. The result is 35 = (100011) 2. Example Convert the decimal number 0.625 to binary. Since the number 0.625 = (0.101)2 has no integral part, the example shows how the fractional part is calculated.
  • 88. Decimal (Fraction) to Binary Conversion    Multiply the number by the ‘Base’ (=2) Take the integer (either 0 or 1) as a coefficient Take the resultant fraction and repeat the division Example: (0.625) 10 Integer Fraction 0.625 * 2 = 0.25 * 2 = 0.5 * 2 = Answer: Coefficient a -1 = 1 a -2 = 0 a -3 = 1 1 . 25 0 . 5 1 . 0 (0.625)10 = (0.a-1 a-2 a-3)2 = (0.101)2 MSB LSB
  • 89.
  • 90. A similar method can be used to convert a decimal fraction to binary when the denominator is a power of two: Exampl e The answer is then (0.011011)2
  • 91. Example An alternative method for converting a small decimal integer (usually less than 256) to binary is to break the number as the sum of numbers that are equivalent to the binary place values shown:
  • 93. Binary to Decimal  Technique    Multiply each bit by 2n, where n is the “weight” of the bit The weight is the position of the bit, starting from 0 on the right Add the results
  • 96. Example The following shows how to convert the binary number (110.11)2 to decimal: (110.11)2 = 6.75.
  • 99. Decimal to Octal Conversion Example (175) 10 Quotient Remainder 175 / 8 = 21 / 8 = 2 / 8 = 21 7 2 5 0 2 Answer: Example (0.3125) 10 Answer: a0 = 7 a1 = 5 a2 = 2 (175)10 = (a2 a1 a0)8 = (257)8 Integer Fraction 0.3125 * 8 = 0.5 * 8 = Coefficient 2 . 5 4 . 0 Coefficient a -1 = 2 a -2 = 4 (0.3125)10 = (0.a-1 a-2 a-3)8 = (0.24)8
  • 100. Example The following shows how to convert 126 in decimal to its equivalent in the octal system. We move to the right while continuously finding the quotients and the remainder of division by 8. The result is 126 = (176)8. Example The following shows how to convert 0.634 to octal using a maximum of four digits. The result is 0.634 = (0.5044)8. Note that we multiple by 8 (base octal).
  • 102. Octal to Decimal  Technique    Multiply each bit by 8 n , where n is the “weight” of the bit The weight is the position of the bit, starting from 0 on the right Add the results 86 85 262144 10 32768 10 84 4096 10 83 512 10 82 64 10 8 10 81 1 10 80
  • 103. Example The following shows how to convert (724)8 to decimal. Example The following shows how to convert (23.17)8 to decimal. This means that (23.17)8 ≈ 19.234 in decimal. Again, we have rounded up 7 × 8−2 = 0.109375.
  • 106. Example The following shows how we convert 126 in decimal to its equivalent in the hexadecimal system. We move to the right while continuously finding the quotients and the remainder of division by 16. The result is 126 = (7E) 16 Example The following shows how to convert 178.6 in decimal to hexadecimal using only one digit to the right of the decimal point. The result is 178.6 = (B2.9) 16 Note that we divide or multiple by 16 (base hexadecimal).
  • 108. Hexadecimal to Decimal  Technique    Multiply each bit by 16n, where n is the “weight” of the bit The weight is the position of the bit, starting from 0 on the right Add the results 16 5 16 0 1048576 10 16 4 65536 10 16 3 4096 10 16 2 256 10 16 10 16 1 1 10
  • 109. Example The following shows how decimal. ABC16 => C x 160 B x 161 A x 162 Example to convert the hexadecimal number (ABC) 16 to = 12 x 1 = 12 = 11 x 16 = 176 = 10 x 256 = 2560 274810 The following shows how to convert the hexadecimal number (1A.23) 16 to decimal. Note :- The result in the decimal notation is not exact, because 3 × 16−2 = 0.01171875. We have rounded this value to three digits (0.012).
  • 110. Base N to Decimal conversion Decimal to Base N Conversions  To convert from decimal to a different number base such as Octal, Binary or Hexadecimal involves repeated division by that number base  Keep dividing until the quotient is zero  Use the remainders in reverse order as the digits of the converted number
  • 112. Binary-octal conversion 8 = 23 Each group of 3 bits represents an octal digit Group bits in threes, starting on right Convert to octal digits
  • 113. Binary − Octal Conversion Example Octal 1 6 . 2 3 )8 Example 10110101112 = ?8 1 011 010 111 1 3 2 7 010 011 100 5 101 6 ( 2 001 2 )2 000 4 ( 10110.01 Binary 0 Assume Zeros 110 7 111 10110101112 = 13278 Works both ways (Binary to Octal & Octal to Binary)
  • 114. Example What is the binary equivalent of for (24)8? Solution Write each octal digit as its equivalent bit pattern to get 2 → 010 and 4 → 100 The result is (010100)2. Example Show the octal equivalent of the binary number (101110010) 2. Solution Each group of three bits is translated into one octal digit. The equivalent of each 3-bit group is shown in Table on above page 101 (101110010)2 = (562)8. 110 010
  • 116. Octal to Binary • Technique • Convert each octal digit to a 3-bit equivalent binary representation • Useful to represent binary numbers indirectly  Octal and binary are nicely related; i.e. 8 = 23  Each octal digit represent 3 binary digits (bits) Example 7058 = ?2 7 0 5 111 000 101 7058 = 1110001012
  • 118. Binary-hexadecimal conversion Technique Group bits in fours, starting on right Convert to hexadecimal digits
  • 119. Binary − Hexadecimal Conversion   16 = 24 Each group of 4 bits represents a hexadecimal digit Example: Assume Zeros ( 1 ( 1 0110. 01 6 . 4 )2 )16 Works both ways (Binary to Hex & Hex to Binary)
  • 120.
  • 121. Example Show the hexadecimal (110011100010)2. equivalent of the binary number Solution We first arrange the binary number in 4-bit patterns: 1100 1110 0010 Note that the leftmost pattern can have one to four bits. We then use the equivalent of each pattern shown in Table 2.2 on page 25 to change the number to hexadecimal: (4E2)16. Example
  • 123. Hexadecimal to Binary   Technique  Convert each hexadecimal digit to a 4-bit equivalent binary representation Useful to represent binary numbers indirectly  Hex and binary are nicely related; i.e. 16 = 2 4  Each hex digit represent 4 binary digits (bits)
  • 124. Example 10AF16 = ?2 1 0 A F 0001 0000 1010 1111 10AF16 = 00010000101011112 Example What is the binary equivalent of (24C)16? Each hexadecimal digit is converted to 4-bit patterns: 2 → 0010, 4 → 0100, and C → 1100 The result is (001001001100)2
  • 127. Conversion  Convert to Binary as an intermediate step Example ( ( 2 6 . 2 0 01 0110.010 0 Assume Zeros ( )8 )2 Assume Zeros 1 6 . 4 )16 Works both ways (Octal to Hex & Hex to Octal)
  • 129. Decimal, Binary, Octal and Hexadecimal Decimal Binary Octal Hex 00 0000 00 0 01 0001 01 1 02 0010 02 2 03 0011 03 3 04 0100 04 4 05 0101 05 5 06 0110 06 6 07 0111 07 7 08 1000 10 8 09 1001 11 9 10 1010 12 A 11 1011 13 B 12 1100 14 C 13 1101 15 D 14 1110 16 E 15 1111 17 F
  • 130. Example Find the minimum number of binary digits required to store decimal integers with a maximum of six digits. k = 6, b1 = 10, and b2 = 2. Then x = [ k × (logb1 / logb2) ] = [6 × (1 / 0.30103)]= 20. The largest six-digit decimal number is 999,999 and the largest 20-bit binary number is 1,048,575. Note that the largest number that can be represented by a 19-bit number is 524287, which is smaller than 999,999. We definitely need twenty bits.
  • 132. Conversion  Convert to Binary as an intermediate step Example ( 1 6 . 4 )16 ( 0 0 0 1 0 1 1 0 . 01 0 0 )2 Assume Zeros ( 2 6 . 2 )8 Assume Zeros Works both ways (Octal to Hex & Hex to Octal)
  • 134. Exercise – Convert ... Decimal Binary Octal Hexadecimal 33 1110101 703 1AF Decimal Binary Octal Hexadecimal 33 100001 41 21 117 1110101 165 75 451 111000011 703 1C3 431 110101111 657 1AF
  • 135. Common Powers (1 of 2)  Base 10 Power Preface Symbol Value 10-12 pico p .000000000001 10-9 nano n .000000001 10-6 micro µ .000001 10-3 milli m .001 103 kilo k 1000 106 mega M 1000000 109 giga G 1000000000 1012 tera T 1000000000000
  • 136. Common Powers (2 of 2)  Base 2 Power Preface Symbol Value 210 kilo k 1024 220 mega M 1048576 230 Giga G 1073741824 • What is the value of “k”, “M”, and “G”? • In computing, particularly w.r.t. memory, the base-2 interpretation generally applies
  • 138.
  • 139. Bits, Bytes, and Words        A bit is a single binary digit (a 1 or 0). A byte is 8 bits A word is 32 bits or 4 bytes Long word = 8 bytes = 64 bits Quad word = 16 bytes = 128 bits Programming languages use these standard number of bits when organizing data storage and access. What do you call 4 bits? (hint: it is a small byte)
  • 141. Decimal Addition 1 1 Carry 5 + 1 5 5 5 1 0 = Ten ≥ Base Base  Subtract a
  • 142. Binary Addition  Column Addition Carry 1 1 1 1 1 1 1 1 1 1 0 1 = 61 1 0 1 1 1 = 23 1 0 1 0 1 0 0 = 84 + ≥ (2) 10
  • 144. Octal Addition Example a. 123 8 + 321 8 = ? 123 8 +321 8 444 8 c. 733 8 + 74 8 = ? b. 4578 + 2458 = ? 4578 + 2458 7248
  • 145. Example Hexadecimal Addition a. 33 16 + 47 16 = ? 33 16 + 47 16 7A 16 b. 20D316 + 12BC16 = ? 20D316 + 12BC16 338F16 Note:- 2410 =1A16 c. DF 16 + AB 16 = ? d. ADC 16 + DEF 16 = ?
  • 146. Addition  Question: What is the result of adding 1 to the largest digit of some number system? • (9)10 + 1 = (10)10 • (7)8 + 1 = (10)8 • (1)2 + 1 = (10)2 • (F)16 + 1 = (10)16  Conclusion: Adding 1 to the largest digit in any number system always has a result of (10) in that number system.
  • 147. Binary Subtraction Borrow a “Base” when needed Borrow 2 from next line 1 2 0 2 2 0 0 2 1 0 0 1 1 0 1 − = 77 1 0 1 1 1 = 23 0 1 1 0 1 1 0 = 54 (2= 10) 2
  • 148. Binary Subtraction Perform the binary subtraction of the following numbers: 10101 and 01110 A B A-B Borrow 0 0 0 0 0 1 1 1 1 0 1 0 1 1 0 0
  • 149. Octal Subtraction a. 524 8 - 167 8 = ? 5 2 4 - (4) 1 3 1 4 8 (8+4) (1+8 ) (12) (9) 6 3 (12) 524 8 - 167 8 = 335 8 7 5 8 8
  • 150. Octal Subtraction a. 524 8 - 167 8 = ? 5 2 4 - 1 48 (1+8) b. 1678 - 248 = ? (8+4) (12) (4) (9) (12) 1 6 78 3 3 c. 1523 8 - 364 8 = ? 524 8 - 167 8 = 335 8 58 167 8 24 8 143 8
  • 151. Hexadecimal Subtraction a . 44 16 - 17 16 =? 3 4 (3) - 1 2 2 44 16 - 17 16 = 2D 16 4 16 (16 + 4) 16 (20) 16 7 16 (13) D 16 16
  • 152. Hexadecimal Subtraction b. 20D316 - 12BC16 = ? a. 44 16 - 17 16 =? 4 3 (3) - 1 2 2 4 16 (16 + 4) (20) 7 16 (13) D 16 44 16 - 17 16 = 2D 16 c. DF 16 - AB 16 = ? 20D316 - 12BC16 0E1716
  • 153. Binary Multiplication Bit by bit Example 1 0 1 1 1 x 1 0 1 0 0 0 0 0 0 1 0 1 1 1 0 0 0 0 0 1 0 1 1 1 1 1 1 0 0 1 1 0
  • 154. Binary Multiplication Example : Perform the binary multiplication of the decimal numbers 12 and 10. The equivalent binary representation of the decimal number 12 is 1100. The equivalent binary representation of the decimal number 10 is 1010
  • 155. Octal Multiplication Example 25 8 * 16 8 = ? Method 1 25 8 * 16 8 =446 8
  • 160. Binary Division  • • Binary division is also performed in the same way as we perform decimal division. Like decimal division, we also need to follow the binary subtraction rules while performing the binary division. The dividend involved in binary division should be greater than the divisor. The following are the two important points, which need to be remembered while performing the binary division. If the remainder obtained by the division process is greater than or equal to the divisor, put 1 in the quotient and perform the binary subtraction. If the remainder obtained by the division process is less than the divisor, put 0 in the quotient and append the next most significant digit from the dividend to the remainder.
  • 161. Binary Division Example The equivalent binary representation of the decimal number 18 is 10010. The equivalent binary representation of the decimal number 8 is 1000.
  • 162. Example Binary Division Find the quotient and remainder when 1111101 is divided by 1101 in modulo 2 arithmetic. We find the quotient is 1011, and the remainder is 0010. This procedure is very useful to us in calculating CRC syndromes
  • 168. Example Octal Division 73 8 ÷ 4 8 = ? 73 8 ÷ 4 8 = 16 8 remain 3
  • 169. Example Octal Division 17534 8 ÷ 64 8 = ? 64 8 × 2 = 150 8 64 8 × 3 = 234 8
  • 170. Example Hexadecimal Division AB 16 ÷ 3 16 = ? AB 16 ÷ 3 16 = 39 16 AB 16 ÷ C 16 = ? AB 16 ÷ C 16 = E.25 16
  • 171. Example Hexadecimal Division DEF 16 ÷ AB 16 = ? Note :- Short method AB 16 =10*16 + 11 160+11 171 DE 16 = 13*16 + 14 208 + 14 222 51*16+F=816 + 15 = 831 171*4 = 5C4 171*E = 142E 171*2 = 2E2
  • 172. Summary of the Division
  • 173.
  • 175. What is an Operator?     Operator is an operation performed over data at runtime  Takes one or more arguments (operands)  Produces a new value Operators have precedence  Precedence defines which will be evaluated first Expressions are sequences of operators and operands that are evaluated to a single value Operators can be classified according to  the type of their operands and of their output  Arithmetic  Relational  Logical  Bitwise  the number of their operands  Unary (one operand)  Binary (two operands)
  • 176. Categories of Operators in C# Category Operators Arithmetic + - * / % ++ -- Relational < <= > >= == != Logical && || ^ ! Binary & | ^ ~ << >> Comparison == != < > <= >= Assignment = += -= *= /= %= &= |= ^= <<= >>= String concatenation + Type conversion is as typeof Other . [] () ?: new
  • 178. Relational operators    These perform comparisons and the result is what is called a boolean: a value TRUE or FALSE FALSE is represented by 0; anything else is TRUE The relational operators are:       < <= > >= == != (less than) (less than or equal to) (greater than) (greater than or equal to) (equal to) (not equal to)
  • 179. Logical Operators (also called Boolean operators)   These have Boolean operands and the result is also a Boolean. The basic Boolean operators are: && (logical AND)   || (logical OR) ! (logical NOT) -- unary Operator ! turns true to false and false to true Behavior of the operators &&, || and ^ (1 == true, 0 == false) Example :bool a = true; bool b = false; (a && b) False (a || b) True (a ^ b) True (!b) True (b || true) True (b && true) False (a || true) True (a && true) True (!a) False ((5>7) ^ (a==b)) False
  • 181. Logical Operators (also called Boolean operators) Operation && && && && Operand1 0 0 1 1 Operand2 0 1 0 1 Result 0 0 0 1 Operation ^ ^ ^ ^ Operand1 0 0 1 1 Operand2 0 1 0 1 Result 0 1 1 0 Operation || || || || Operand1 0 0 1 1 Operand2 0 1 0 1 Result 0 1 1 1
  • 182. BITWISE OPERATORS Bitwise operators operate on individual bits of integer (int and long) values. If an operand is shorter than an int, it is promoted to int before doing the operations. Negative integers are store in two's complement form. For example, -4 is 1111 1111 1111 1111 1111 1111 1111 1100. Bitwise operator ~ turns all 0 to 1 and all 1 to 0 expressions but bit by bit Like ! for boolean The operators |, & and ^ behave like ||, && and ^ for Boolean expressions but bit by bit The << and >> move the bits (left or right) Bitwise operators are used on integer numbers (byte, sbyte, int, uint, long, ulong) Bitwise operators are applied bit by bit
  • 183. Bitwise Operator Operator Value ~ Bitwise unary NOT & Bitwise AND | Bitwise OR ^ Bitwise XOR >> >>> Shift Right Shift Right zero fill << Shift left & = Bitwise AND Assignment |= Bitwise OR Assignment ^= Bitwise XOR Assignment >>= >>>= <<= Shift Right Assignment Shift Right zero fill Assignment Shift Left Assignment
  • 184. Bitwise Operator { NOT A } as ∼A { A AND B } as A AND B=A × B A & B=A × B A ∼A 0 1 1 NOT A = 0 A B A×B 0 0 0 0 1 0 1 0 0 1 1 1
  • 185. Bitwise Operator { A OR B } as follows A OR B=A+B A | B=A+B A B A+B { A OR B OR C} as follows A OR B OR C =A+B+C A | B | C= A+B+C A B C A+B+C 0 0 0 0 0 0 1 1 0 0 0 0 1 1 0 1 0 1 0 1 1 1 1 0 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1
  • 186. Bitwise Operator { A XOR B } as A XOR B = (∼A)B + A(∼B) A ^ B = ( ∼A)B + A(∼B) B A⊗B 0 0 0 0 1 1 1 0 1 1 Summary A 1 0
  • 187. BITWISE OPERATORS Ope ration | | | | & & & & ^ ^ ^ ^ Ope rand1 0 0 1 1 0 0 1 1 0 0 1 1 Ope rand2 0 1 0 1 0 1 0 1 0 1 0 1 Re s ult 0 1 1 1 0 0 0 1 0 1 1 0 Examples: a = 3; is 00000011 b = 5; is 00000101 ( a | b); // 00000111 ( a & b); // 00000001 ( a ^ b); // 00000110 (~a & b); // 00000100 ( a<<1 ); // 00000110 ( a>>1 ); // 00000001
  • 192. <-------Bitwise Logical Operators-------> Example :- The binary value of a = 0010 and b = 0111 1.The Bitwise OR : a | b = 7 2.The Bitwise AND : a & b = 2 3.The Bitwise XOR(exclusive OR) : a ^ b = 5 4.The Bitwise unary NOT : ~a & a = 0 5.~a&b|a&~b = 5 <-------Bitewise Shift Operators-------> Example :- The original binary value of a = 0010 and Decimal value of a = 2 1.The Left shift : a = 8 2. The Right shift : b = b >> 2 = 1 3.The original decimal value of u = -1 4. The Unsigned Right shift : u = u >>> 30 means u = 11111111 11111111 11111111 11111111 >>> 30 hence u = 0011 and Decimal value of u = 3 <-------Bitewise Assignment Operators-------> Example :- The original binary value of p = 0101 and Decimal value of p = 5 1.The Bitewise Shift Right Assignment Operators : p >>= 2 means p = p >> hence p =0101 >> 2 so p = 0001 and Decimal value of p = 1
  • 193. Bitwise Operator Bitwise operators are used in 1.Communication stacks where the individual bits in the header attached to the data signify important information 2.Embedded software for controlling different functions in the chip and indicating the status of hardware by manipulating the individual bits of hardware registers of embedded microcontrollers 3.Low-level programming for applications such as device drivers, cryptographic software, video decoding software, memory allocators, compression software and graphics 4.Maintaining large sets of integers efficiently in search and optimization problems 5.Bitwise operations performed on bit flags, which can enable an instance of enumeration type to store any combination of values defined in an enumerator list
  • 194. Low level languages are: 1 - Machine Language 2 - Assembly Language 3 - C (C is not the 100% Low-level language) High level languages are: 1 - Visual Basic 2 - Pascal 3 - Java 4 - C++ and many more.