Uinit1 Numbersystem

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

Subject Name: Compute

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)

Decimal 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.

S.No. Number System and Description

1 Binary Number System


Base 2. Digits used : 0, 1
Octal Number System
2
Base 8. Digits used : 0 to 7

Hexa Decimal Number System


3
Base 16. Digits used: 0 to 9, Letters used : A- F

Binary Number System

Characteristics of the binary number system are as follows −


 Uses two digits, 0 and 1
 Also called as base 2 number system
 Each position in a binary number represents a 0 power of the base (2). Example 20
 Last position in a binary number represents a x power of the base (2). Example
2x where x represents the last position - 1.

Example

Binary Number: 101012


Calculating Decimal Equivalent −

Step Binary Number Decimal Number

Step 1 101012 ((1 x 24) + (0 x 23) + (1 x 22) + (0 x 21) + (1 x 20))10

Step 2 101012 (16 + 0 + 4 + 0 + 1)10

Step 3 101012 2110

Note − 101012 is normally written as 10101.

Octal Number System

Characteristics of the octal number system are as follows −


 Uses eight digits, 0,1,2,3,4,5,6,7
 Also called as base 8 number system
 Each position in an octal number represents a 0 power of the base (8). Example 80
 Last position in an octal number represents a x power of the base (8). Example
8x where x represents the last position - 1

Example

Octal Number: 125708


Calculating Decimal Equivalent −

Step Octal Number Decimal Number

Step 1 125708 ((1 x 84) + (2 x 83) + (5 x 82) + (7 x 81) + (0 x 80))10

Step 2 125708 (4096 + 1024 + 320 + 56 + 0)10

Step 3 125708 549610

Note − 125708 is normally written as 12570.

Hexadecimal Number System

Characteristics of hexadecimal number system are as follows −


 Uses 10 digits and 6 letters, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
 Letters represent the numbers starting from 10. A = 10. B = 11, C = 12, D = 13, E = 14,
F = 15
 Also called as base 16 number system
 Each position in a hexadecimal number represents a 0 power of the base (16). Example,
160
 Last position in a hexadecimal number represents a x power of the base (16). Example
16x where x represents the last position - 1

Example
Hexadecimal Number: 19FDE16
Calculating Decimal Equivalent −

Step Binary Decimal Number


Number

Step 1 19FDE16 ((1 x 164) + (9 x 163) + (F x 162) + (D x 161) + (E x 160))10

Step 2 19FDE16 ((1 x 164) + (9 x 163) + (15 x 162) + (13 x 161) + (14 x 160))10

Step 3 19FDE16 (65536+ 36864 + 3840 + 208 + 14)10

Step 4 19FDE16 10646210

Note − 19FDE16 is normally written as 19FDE.


The technique to represent and work with numbers is called number system. Decimal number
system is the most common number system. Other popular number systems include binary
number system, octal number system, hexadecimal number system, etc.

Decimal Number System

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−

 In 734, value of 7 is 7 hundreds or 700 or 7 × 100 or 7 × 102


 In 971, value of 7 is 7 tens or 70 or 7 × 10 or 7 × 101
 In 207, value 0f 7 is 7 units or 7 or 7 × 1 or 7 × 100
The weightage of each position can be represented as follows −
In digital systems, instructions are given through electric signals; variation is done by varying
the voltage of the signal. Having 10 different voltages to implement decimal number system in
digital equipment is difficult. So, many number systems that are easier to implement digitally
have been developed. Let’s look at them in detail.

Binary Number System

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.

 1 byte (B) = 8 bits


 1 Kilobytes (KB) = 1024 bytes
 1 Megabyte (MB) = 1024 KB
 1 Gigabyte (GB) = 1024 MB
 1 Terabyte (TB) = 1024 GB
 1 Exabyte (EB) = 1024 PB
 1 Zettabyte = 1024 EB
 1 Yottabyte (YB) = 1024 ZB

Octal Number System

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

Hexadecimal Number System

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 −

HEXADECIMAL DECIMAL OCTAL BINARY

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

2. Conversion of Numbering System:

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

Binary to Octal and Vice Versa

To convert a binary number to octal number, these steps are followed −


 Starting from the least significant bit, make groups of three bits.
 If there are one or two bits less in making the groups, 0s can be added after the most
significant bit
 Convert each group into its equivalent octal number
Let’s take an example to understand this.
101100101012 = 26258
To convert an octal number to binary, each octal digit is converted to its 3-bit binary equivalent
according to this table.

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

To convert a binary number to hexadecimal number, these steps are followed −


 Starting from the least significant bit, make groups of four bits.
 If there are one or two bits less in making the groups, 0s can be added after the most
significant bit.
 Convert each group into its equivalent octal number.
Let’s take an example to understand this.

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.

Representation of Unsigned Binary Numbers:


Since there is no sign bit in this unsigned binary number, so N bit binary number represent its
magnitude only. Zero (0) is also unsigned number. This representation has only one zero (0),
which is always positive. Every number in unsigned number representation has only one unique
binary equivalent form, so this is unambiguous representation technique. The range of unsigned
binary number is from 0 to (2n-1).
Example-1: Represent decimal number 92 in unsigned binary number.
Simply convert it into Binary number, it contains only magnitude of the given number.
= (92)10
= (1x26+0x25+1x24+1x23+1x22+0x21+0x20)10
= (1011100)2
It’s 7 bit binary magnitude of the decimal number 92.

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.

Representation of Signed Binary Numbers:


There are three types of representations for signed binary numbers. Because of extra signed bit,
binary number zero has two representation, either positive (0) or negative (1), so ambiguous
representation. But 2’s complementation representation is unambiguous representation because
of there is no double representation of number 0. These are: Sign-Magnitude form, 1’s
complement form, and 2’s complement form which are explained as following below.
3.2.(a) Sign-Magnitude form:
For n bit binary number, 1 bit is reserved for sign symbol. If the value of sign bit is 0, then the
given number will be positive, else if the value of sign bit is 1, then the given number will be
negative. Remaining (n-1) bits represent magnitude of the number. Since magnitude of number
zero (0) is always 0, so there can be two representation of number zero (0), positive (+0) and
negative (-0), which depends on value of sign bit. Hence these representations are ambiguous
generally because of two representation of number zero (0). Generally sign bit is a most
significant bit (MSB) of representation. The range of Sign-Magnitude form is from (2(n-1)-1) to
(2(n-1)-1).
For example, range of 6 bit Sign-Magnitude form binary number is from (25-1) to (25-1) which
is equal from minimum value -31 (i.e., 1 11111) to maximum value +31 (i.e., 0 11111). And
zero (0) has two representation, -0 (i.e., 1 00000) and +0 (i.e., 0 00000).
3.2.(b) 1’s complement form:
Since, 1’s complement of a number is obtained by inverting each bit of given number. So, we
represent positive numbers in binary form and negative numbers in 1’s complement form. There
is extra bit for sign representation. If value of sign bit is 0, then number is positive and you can
directly represent it in simple binary form, but if value of sign bit 1, then number is negative and
you have to take 1’s complement of given binary number. You can get negative number by 1’s
complement of a positive number and positive number by using 1’s complement of a negative
number. Therefore, in this representation, zero (0) can have two representation, that’s why 1’s
complement form is also ambiguous form. The range of 1’s complement form is from (2(n-1)-1)
to (2(n-1)-1) .
For example, range of 6 bit 1’s complement form binary number is from (25-1) to (25-1) which
is equal from minimum value -31 (i.e., 1 00000) to maximum value +31 (i.e., 0 11111). And
zero (0) has two representation, -0 (i.e., 1 11111) and +0 (i.e., 0 00000).
3. 2.(c) 2’s complement form:
Since, 2’s complement of a number is obtained by inverting each bit of given number plus 1 to
least significant bit (LSB). So, we represent positive numbers in binary form and negative
numbers in 2’s complement form. There is extra bit for sign representation. If value of sign bit is
0, then number is positive and you can directly represent it in simple binary form, but if value of
sign bit 1, then number is negative and you have to take 2’s complement of given binary
number. You can get negative number by 2’s complement of a positive number and positive
number by directly using simple binary representation. If value of most significant bit (MSB) is
1, then take 2’s complement from, else not. Therefore, in this representation, zero (0) has only
one (unique) representation which is always positive. The range of 2’s complement form is from
(2(n-1)) to (2(n-1)-1).
For example, range of 6 bit 2’s complement form binary number is from (25) to (25-1) which is
equal from minimum value -32 (i.e., 1 00000) to maximum value +31 (i.e., 0 11111). And zero
(0) has two representation, -0 (i.e., 1 11111) and +0 (i.e., 0 00000).
4. Arithmetic Operations of Binary Numbers
Binary is a base-2 number system that uses two states 0 and 1 to represent a number. We can also
call it to be a true state and a false state. A binary number is built the same way as we build the
normal decimal number.
Binary arithmetic is an essential part of various digital systems. You can add, subtract, multiply,
and divide binary numbers using various methods. These operations are much easier than
decimal number arithmetic operations because the binary system has only two digits: 0 and 1.
Binary additions and subtractions are performed as same in decimal additions and subtractions.
When we perform binary additions, there will be two outputs: Sum (S) and Carry (C).
1. There are four rules for binary addition:
2. There are four rules for binary subtraction:
Here 0-1 should be 1 and 1
Borrow 1 is required from the next higher order bit to subtract 1 from 0. So, the result became 0.
3. There are four rules for binary multiplication:

Multiplication is always 0, whenever at least one input is 0.


4. There are four parts in any division: Dividend, Divisor, quotient, and remainder.
5. Logical Operations on Bits

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:

Table 5: AND Truth Table


AND 0 1

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.

The logical OR operation is also a dyadic operation. Its definition is:

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:

Table 6: OR Truth Table

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:

Table 7: XOR Truth Table

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:

Table 8: NOT Truth Table

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 << 1 → 0100


0010 << 2 → 1000

A single left shift multiplies a binary number by 2:

0010 << 1 → 0100

0010 is 2
0100 is 4

Logical Right Shifts


When shifting right with a logical right shift, the least-significant bit is lost and a 00 is inserted
on the other end.

1011 >>> 1 → 0101


1011 >>> 3 → 0001

For positive numbers, a single logical right shift divides a number by 2, throwing out any
remainders.

0101 >>> 1 → 0010

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 −

 26 upper case letters


 26 lower case letters
 10 digits
 7 punctuation marks
 20 to 40 special characters
Now a computer understands only numeric values, whatever the number system used. So all
characters must have a numeric equivalent called the alphanumeric code. The most widely used
alphanumeric code is American Standard Code for Information Interchange (ASCII). ASCII is a
7-bit code that has 128 (27) possible codes.

You might also like