Uinit1 Numbersystem
Uinit1 Numbersystem
Uinit1 Numbersystem
1.Numbering System
When we type some letters or words, the computer translates them in numbers as computers can
understand only numbers. A computer can understand the positional number system where there
are only a few symbols called digits and these symbols represent different values depending on
the position they occupy in the number.
The value of each digit in a number can be determined using −
The digit
The position of the digit in the number
The base of the number system (where the base is defined as the total number of digits
available in the number system)
The number system that we use in our day-to-day life is the decimal number system. Decimal
number system has base 10 as it uses 10 digits from 0 to 9. In decimal number system, the
successive positions to the left of the decimal point represent units, tens, hundreds, thousands,
and so on.
Each position represents a specific power of the base (10). For example, the decimal number
1234 consists of the digit 4 in the units position, 3 in the tens position, 2 in the hundreds
position, and 1 in the thousands position. Its value can be written as
(1 x 1000)+ (2 x 100)+ (3 x 10)+ (4 x l)
(1 x 103)+ (2 x 102)+ (3 x 101)+ (4 x l00)
1000 + 200 + 30 + 4
1234
As a computer programmer or an IT professional, you should understand the following number
systems which are frequently used in computers.
Example
Example
Example
Hexadecimal Number: 19FDE16
Calculating Decimal Equivalent −
Step 2 19FDE16 ((1 x 164) + (9 x 163) + (15 x 162) + (13 x 161) + (14 x 160))10
Decimal number system is a base 10 number system having 10 digits from 0 to 9. This means
that any numerical quantity can be represented using these 10 digits. Decimal number system is
also a positional value system. This means that the value of digits will depend on its position.
Let us take an example to understand this.
Say we have three numbers – 734, 971 and 207. The value of 7 in all three numbers is
different−
The easiest way to vary instructions through electric signals is two-state system – on and off.
On is represented as 1 and off as 0, though 0 is not actually no signal but signal at a lower
voltage. The number system having just these two digits – 0 and 1 – is called binary number
system.
Each binary digit is also called a bit. Binary number system is also positional value system,
where each digit has a value expressed in powers of 2, as displayed here.
In any binary number, the rightmost digit is called least significant bit (LSB) and leftmost digit
is called most significant bit (MSB).
And decimal equivalent of this number is sum of product of each digit with its positional value.
110102 = 1×24 + 1×23 + 0×22 + 1×21 + 0×20
= 16 + 8 + 0 + 2 + 0
= 2610
Computer memory is measured in terms of how many bits it can store. Here is a chart for
memory capacity conversion.
Octal number system has eight digits – 0, 1, 2, 3, 4, 5, 6 and 7. Octal number system is also a
positional value system with where each digit has its value expressed in powers of 8, as shown
here −
Decimal equivalent of any octal number is sum of product of each digit with its positional
value.
7268 = 7×82 + 2×81 + 6×80
= 448 + 16 + 6
= 47010
Octal number system has 16 symbols – 0 to 9 and A to F where A is equal to 10, B is equal to
11 and so on till F. Hexadecimal number system is also a positional value system with where
each digit has its value expressed in powers of 16, as shown here −
0 0 0 0000
1 1 1 0001
2 2 2 0010
3 3 3 0011
4 4 4 0100
5 5 5 0101
6 6 6 0110
7 7 7 0111
8 8 10 1000
9 9 11 1001
A 10 12 1010
B 11 13 1011
C 12 14 1100
D 13 15 1101
E 14 16 1110
F 15 17 1111
Decimal equivalent of any hexadecimal number is sum of product of each digit with its
positional value.
27FB16 = 2×163 + 7×162 + 15×161 + 10×160
= 8192 + 1792 + 240 +10
= 1023410
As you know decimal, binary, octal and hexadecimal number systems are positional value
number systems. To convert binary, octal and hexadecimal to decimal number, we just need to
add the product of each digit with its positional value. Here we are going to learn other
conversion among these number systems.
Decimal to Binary
Decimal numbers can be converted to binary by repeated division of the number by 2 while
recording the remainder. Let’s take an example to see how this happens.
The remainders are to be read from bottom to top to obtain the binary equivalent.
4310 = 1010112
Binary to Decimal
(1010.01)2
1x23 + 0x22 + 1x21+ 0x20 + 0x2 -1 + 1x2 -2 = 8+0+2+0+0+0.25 = 10.25
(1010.01)2 = (10.25)10
Octal Digit 0 1 2 3 4 5 6 7
Binary Equivalent 000 001 010 011 100 101 110 111
546738 = 1011001101110112
Binary to Hexadecimal
101101101012 = DB516
To convert an octal number to binary, each octal digit is converted to its 3-bit binary equivalent.
3. Representation of Binary Numbers:
Binary numbers can be represented in signed and unsigned way. Unsigned binary numbers do
not have sign bit, whereas signed binary numbers uses signed bit as well or these can be
distinguishable between positive and negative numbers. A signed binary is a specific data type
of a signed variable.
3. 1. Unsigned Numbers:
Unsigned numbers don’t have any sign, these can contain only magnitude of the number. So,
representation of unsigned binary numbers are all positive numbers only. For example,
representation of positive decimal numbers are positive by default. We always assume that there
is a positive sign symbol in front of every number.
Example-2: Find range of 5 bit unsigned binary numbers. Also, find minimum and maximum
value in this range.
Since, range of unsigned binary number is from 0 to (2n-1). Therefore, range of 5 bit unsigned
binary number is from 0 to (25-1) which is equal from minimum value 0 (i.e., 00000) to
maximum value 31 (i.e., 11111).
3.2. Signed Numbers:
Signed numbers contain sign flag, this representation distinguish positive and negative numbers.
This technique contains both sign bit and magnitude of a number. For example, in representation
of negative decimal numbers, we need to put negative symbol in front of given decimal number.
There are four main logical operations we'll need to perform on hexadecimal and binary
numbers: AND, OR, XOR (exclusive-or), and NOT. Unlike the arithmetic operations, a
hexadecimal calculator isn't necessary to perform these operations. It is often easier to do them
by hand than to use an electronic device to compute them. The logical AND operation is a
dyadic1 operation (meaning it accepts exactly two operands). These operands are single binary
(base 2) bits. The AND operation is:
0 and 0 = 0
0 and 1 = 0
1 and 0 = 0
1 and 1 = 1
A compact way to represent the logical AND operation is with a truth table. A truth table takes
the following form:
0 0 0
1 0 1
This is just like the multiplication tables you encountered in elementary school. The values in the
left column correspond to the leftmost operand of the AND operation. The values in the top row
correspond to the rightmost operand of the AND operation. The value located at the intersection
of the row and column (for a particular pair of input values) is the result of logically ANDing
those two values together.
In English, the logical AND operation is, "If the first operand is one and the second operand is
one, the result is one; otherwise the result is zero." We could also state this as "If either or both
operands are zero, the result is zero."
One important fact to note about the logical AND operation is that you can use it to force a zero
result. If one of the operands is zero, the result is always zero regardless of the other operand. In
the truth table above, for example, the row labelled with a zero input contains only zeros and the
column labelled with a zero only contains zero results. Conversely, if one operand contains a
one, the result is exactly the value of the second operand. These features of the AND operation
are very important, particularly when we want to force individual bits in a bit string to zero. We
will investigate these uses of the logical AND operation in the next section.
0 or 0 = 0
0 or 1 = 1
1 or 0 = 1
1 or 1 = 1
The truth table for the OR operation takes the following form:
OR 0 1
0 0 1
1 1 1
Colloquially, the logical OR operation is, "If the first operand or the second operand (or both) is
one, the result is one; otherwise the result is zero." This is also known as the inclusive-
OR operation.
If one of the operands to the logical-OR operation is a one, the result is always one regardless of
the second operand's value. If one operand is zero, the result is always the value of the second
operand. Like the logical AND operation, this is an important side-effect of the logical-OR
operation that will prove quite useful when working with bit strings since it lets you force
individual bits to one.
Note that there is a difference between this form of the inclusive logical OR operation and the
standard English meaning. Consider the phrase "I am going to the store or I am going to the
park." Such a statement implies that the speaker is going to the store or to the park but not to
both places. Therefore, the English version of logical OR is slightly different than the inclusive-
OR operation; indeed, it is closer to the exclusive-OR operation.
The logical XOR (exclusive-or) operation is also a dyadic operation. It is defined as follows:
0 xor 0 = 0
0 xor 1 = 1
1 xor 0 = 1
1 xor 1 = 0
The truth table for the XOR operation takes the following form:
XOR 0 1
0 0 1
1 1 0
In English, the logical XOR operation is, "If the first operand or the second operand, but not
both, is one, the result is one; otherwise the result is zero." Note that the exclusive-or operation is
closer to the English meaning of the word "or" than is the logical OR operation.
If one of the operands to the logical exclusive-OR operation is a one, the result is always
the inverse of the other operand; that is, if one operand is one, the result is zero if the other
operand is one and the result is one if the other operand is zero. If the first operand contains a
zero, then the result is exactly the value of the second operand. This feature lets you selectively
invert bits in a bit string.
The logical NOT operation is a monadic operation (meaning it accepts only one operand). It is:
NOT 0 = 1
NOT 1 = 0
The truth table for the NOT operation takes the following form:
NOT 0 1
1 0
6. Shift Operators
A bit shift moves each digit in a number's binary representation left or right. There are three
main types of shifts:
Left Shifts
When shifting left, the most-significant bit is lost, and a 00 bit is inserted on the other end.
The left shift operator is usually written as "<<".
0010 is 2
0100 is 4
For positive numbers, a single logical right shift divides a number by 2, throwing out any
remainders.
0101 is 5
0010 is 2
7.ASCII
Besides numerical data, computer must be able to handle alphabets, punctuation marks,
mathematical operators, special symbols, etc. that form the complete character set of English
language. The complete set of characters or symbols are called alphanumeric codes. The
complete alphanumeric code typically includes −