The document discusses different numeric representation systems used in computing, including decimal, binary, octal, and hexadecimal. It explains key concepts such as positional notation, where the position of a digit determines its value; radix/base, which is the set of digits used; and weighting factors, where each digit position is multiplied by a power of the base to determine its value. Integer, floating point, and fixed point numbers are also defined in terms of how many bits are used for integer and fractional portions.
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.
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.
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.
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
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
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
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.
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
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
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.
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
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
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
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
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
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
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.
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
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)
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
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
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
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
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
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.