2.3 NUMBER SYSTEM
We are familiar with decimal number system which uses ten distinct symbols from 0…9,
and has base 10. In the decimal number system a number n4n3n2n1 is interpreted as
n4×103
+n3×102
+n2×101
+n1×100
. Thus decimal number 5632 represents 5000+600+30+2.
It is a weighted code system since numbers 5632, 2563, 3562, 6532 all represent different
quantities despite the fact that all of them use the same symbols (2,3,5,6). The magnitude/
value of a number is determined both by the symbols used and the places at which they
are present. Thus, symbol 3 at ten’s place represent 30, but when written at thousands’
place it represent 3000. Although we use only the decimal number system in everyday
applications but there are many other number systems possible. In fact, we can have
number system with any base r.
A number system with base r will have r distinct symbols, from 0 to r-1. Binary number
system (r = 2), octal number system (r = 8) and hexadecimal number system (r = 16) are
some of the frequently used number systems in computer science. Binary number system
has two distinct symbols 0 & 1; Octal has seven distinct symbols 0,1,2,3,4,5,6,7; and
Hexadecimal number system has sixteen distinct symbols namely
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F. The numbers written in a particular number system can
be transformed to an equivalent value in a different number system. For example a
number 3F in hexadecimal is equivalent to 63 (3×161
+ F × 160
) in decimal number
system. And similarly a number 302 in octal is equivalent to 194 (3× 8
2
+ 0 × 8
1
+2 × 8
0
)
in decimal number system
2.3.1 Binary Number System
As stated above, the binary number system has base 2 and therefore uses only two
distinct symbols 0 and 1. Any number in binary is written only by using these two
symbols. Though it uses just two symbols but it has enough expressive power to
represent any number. A binary number 1001 thus represents the number 1× 2
3
+ 0 × 2
2
+
0× 2
1
+ 1× 2
0
. It is equivalent to number 9 in decimal number system. Similarly 11001
and 10001 represent numbers 25 and 17 respectively in decimal number system. Please
note that the base in binary number system is 2
A binary number can be converted to its decimal equivalent by forming the sum of
powers of 2 of those coefficients whose value is 1.
For example:
The conversion from decimal to binary or to any other base-r system is done by
separating the number into an integer part and a fraction part and then converting each
part separately. For example the decimal number 41.6875 can be converted to binary
equivalent, by converting the integer and fraction parts separately, as follows:
Operation Quotient Remainder
41 / 2 20 1
20 / 2 10 0
10 / 2 5 0 ⬆
5 / 2 2 1 ⬆
2 / 2 1 0 ⬆
1 / 2 0 1 ⬆
The number is divided by 2 and the remainder part is extracted. The quotient obtained is
again divided by 2 and this process is repeated until the quotient becomes 0. Every time
the remainder obtained is recorded. The set of remainders obtained, read from the bottom
to top form the binary equivalent of the integer part of the number. Thus (41)10 =
(101001)2.
In order to convert the fraction part, it is multiplied by 2 to obtain resultant integer and
fraction parts. The integer part in the resultant is extracted and the fraction part is again
multiplied by 2. This multiplication process is repeated till the fraction part becomes 0 or
a desired precision is achieved. The integer part of the given number (.6875) can be
converted to binary as follows:
Operation Resulting Integer part Resulting Fraction part
0.6875 X 2 1 ↓ .3750
0.3750 X 2 0 ↓ .7500
0.7500 X 2 1 ↓ .5000
0.5000 X 2 1 ↓ .0000
The binary equivalent of fraction 0.6875 is 1011, obtained by reading the integer parts
from top to down. Thus, the decimal number 41.6875 is equivalent to 101001.1011
binary number system.
Conversion
Decimal to Binary:
Q. Convert (13)₁₀ to an equivalent binary number.
Quotient Remainder
13/2 6 1
6/2 3 0
3/2 1 1
1/2 0 1
We take the remainder from bottom to top. Hence (13)₁₀ = (1101)₂
Binary To Decimal
Q. Convert (101011)₂ to an equivalent decimal number.
5 4 3 2 1 0
(1 0 1 0 1 1)₂
= 2⁵ + 2³ + 2 ¹ + 2 ⁰= 32 + 8 + 2 + 1 = 43
Hence, (101011)₂ = 43
2.3.2 Binary Codes
We have seen earlier that digital computers use signals that have two distinct values and
there exists a direct analogy between binary signals and binary digits. Computers not only
manipulate numbers but also other discrete elements of information. The distinct discrete
quantities can be represented by a group of binary digits (known as bits). For example, to
represent two different quantities uniquely two symbols are sufficient and hence one
binary digit (either 0 or 1) will be sufficient to uniquely represent the two symbols. But
one bit will not suffice if one has to represent more than two quantities. In those cases
more than one bits are required, i.e. the bits have to used repeatedly. For example if we
have to give unique codes for three distinct items we need at least 2 bits. With two bits
we can have codes 00, 01, 10 and 11. Out of this we can use first three to assign unique
codes to three distinct quantities and leave the fourth one unused. In general, an n-bit
binary code can be used to represent 2n
distinct quantities. Thus group of two bits can
represent four distinct quantities through unique symbols 00, 01, 10 & 11. Three bits can
be used to represent eight distinct quantities by unique symbols 000, 001, 010, 011, 100,
101, 110 & 111. In other words, to assign unique codes to m distinct items we need at
least n bit code such that 2ⁿ>= m.
Digital computers use binary codes to represent all kinds of information ranging from
numbers to alphabets. Whether we have to input an alphabet, a number or a punctuation
symbol; we need to convey it to machine through a unique code for each item. Thus, the
instruction to be performed by the CPU and the input data which form the operands of the
instruction are represented using a binary code system. A typical machine instruction in a
digital computer system could therefore look like a set of 0s and 1s. Many binary codes
are used in digital systems. BCD code for representing decimal numbers, ASCII code for
information interchange between computer and keyboard, Unicode for use over Internet
and Reflected (Gray) code are some commonly studied binary code systems.
2.3.3 ASCII & Unicode (ASCII is an
alphanumeric code
used for representing
numbers, alphabets,
punctuation symbols
and other control
characters)
An alphanumeric code has to represent 10 decimal digits, 26 alphabets and certain other
symbols such as punctuation marks and special characters. Therefore, a minimum of six
bits is required to code alphanumeric characters (26
= 64, but 25
= 32 is insufficient).
With a few variations this 6 bit code is used to represent alphanumeric characters
internally. However, the need to represent more than 64 characters (to incorporate
lowercase and uppercase letters and special characters), have given rise to seven- and
eight- bit alphanumeric codes. ASCII code is one such seven bit code that is used to
identify key press on the keyboard. ASCII stands for American Standard Code for
Information Interchange. It's an alphanumeric code used for representing numbers,
alphabets, punctuation symbols and other control characters. It’s a seven bit code, but for
all practical purposes it’s an eight bit code, where eighth bit is added for parity. Table 2.1
below presents the ASCII code chart.
ASCII codes represent text in computers, communications equipment, and other devices
that use text. Most modern character-encoding schemes are based on ASCII, though they
support many more characters than did ASCII. Historically, ASCII developed from
telegraphic codes. Its first commercial use was as a seven-bit teleprinter code promoted
by Bell data services. Work on ASCII formally began on October 6, 1960, with the first meeting of the American Standards Association's (ASA) X3.2 subcommittee. The first
edition of the standard was published during 1963 a major revision during 1967, and the
most recent update during 1986. ASCII includes definitions for 128 characters: 33 are
non-printing control characters (now mostly obsolete) that affect how text and space is
processed; 94 are printable characters, and the space is considered an invisible graphic.
The most commonly used character encoding on the World Wide Web was US-ASCII
until December 2007, when it was surpassed by UTF-8.
Unicode (is a
computing
industry standard
for the consistent
encoding,
representation
and handling of
text expressed in
most of the
world's writing
systems)
is a computing industry standard for the consistent encoding, representation and
handling of text expressed in most of the world's writing systems. Developed in
conjunction with the Universal Character Set standard and published in book form as The
Unicode Standard, the latest version of Unicode consists of a repertoire of more than
107,000 characters covering 90 scripts, a set of code charts for visual reference, an
encoding methodology and set of standard character encodings, an enumeration of
character properties such as upper and lower case, a set of reference data computer files,
and a number of related items, such as character properties, rules for normalization,
decomposition, collation, rendering, and bidirectional display order (for the correct
display of text containing both right-to-left scripts, such as Arabic and Hebrew, and leftto-right scripts. Unicode can be implemented by different character encodings. The most
commonly used encodings are UTF-8 (which uses one byte for any ASCII characters,
which have the same code values in both UTF-8 and ASCII encoding, and up to four
bytes for other characters), the now-obsolete UCS-2 (which uses two bytes for each
character but cannot encode every character in the current Unicode standard), and UTF16 (which extends UCS-2 to handle code points beyond the scope of UCS-2).
The Unicode Consortium, the nonprofit organization that coordinates Unicode's
development, has the ambitious goal of eventually replacing existing character encoding
schemes with Unicode and its standard Unicode Transformation Format (UTF) schemes,
as many of the existing schemes are limited in size and scope and are incompatible with
multilingual environments. Unicode's success at unifying character sets has led to its
widespread and predominant use in the internationalization and localization of computer
software. The standard has been implemented in many recent technologies, including
XML, the Java programming language, the Microsoft .NET Framework, and modern
operating systems.
👉Check Your Progress 2
1) Choose the best alternative: (a) ASCII is practically a ………………. bit code:
(i) six (ii) seven (iii) eight (iv) nine
(b) A number system having base r will have ……….. distinct symbols:
(i) r/2 (ii) 2r (iii) r (iv) r2
(c) Unicode is used primarily for:
(i) processing (ii) Internet technologies (iii) logical operations
(d) The binary equivalent of (25.25)10 is:
(i) 11001.001 (ii) 11101.010 (iii) 10001.110
2) State True or False:(a) A decimal number can be converted into its binary equivalent
integer and fraction parts separately.
True False
(b) An n-bit binary code can represent n2
distinct codes.
True False
(c) The most commonly used Unicode Transformation Format
currently is UTF-8.
True False
3) Briefly state the reason why ASCII can not be less than 7 bit code?
4) What was the main motivation behind the development of Unicode?
0 Comments