Introduction to Computer Application, Pritom Paul, NEUB 1
Lecture 1: Numbering System and Computer’s Internal Data Representation
1. Introduction
1.1. Number System
A numbering system is a systematic way to represent numbers using a set of symbols or digits. In
computing, different numbering systems are used to store, process, and represent data internally.
In our everyday life we use 10 symbols ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’.
For example,
⇨ 90328 = 90000 + 300 + 20 + 890328 = 90000 + 300 + 20 + 8
A more sophisticated way of writing it is:
⇨ 90328 = (9 × 10000) + (0 × 1000) + (3 × 100) + (2 × 10) + (8 × 1)
If you've learnt about exponents, you could write it as:
⇨ 90328 = (9 × 104) + (0 × 103) + (3 × 102) + (2 × 101) + (8 × 100)
Remember that any number to the power of 0 is 1. i.e. the 8 x 100 is 8, because the 100 is 1.
This mechanism of writing numbers is known as number system. The base of a number system is the
number of total unique symbols used.
1.2. Types of Number Systems
There are various types of number systems in mathematics. The four most common number system types
are:
1. Decimal number system (Base- 10)
2. Binary number system (Base- 2)
3. Octal number system (Base-8)
4. Hexadecimal number system (Base- 16)
Number System Base Digits Used Example
Decimal 10 0-9 375
Binary 2 0,1 1011₂
Octal 8 0-7 725₈
Hexadecimal 16 0-9, A-F 2F₁₆
1.3. Details of Numbering Systems
1.3.1. Decimal Number System (Base 10)
• Most commonly used by humans.
• Consists of digits 0 to 9.
• Positional value increases by a power of 10.
Example: 52710
1.3.2. Binary Number System (Base 2)
• Used internally by all digital computers.
• Only two digits: 0 and 1.
Example: 1011₂
Decimal 0 1 2 3 4 5 6 7 8 9 10 11
Binary 0 1 10 11 100 101 110 111 1000 1001 1010 1011
Power of Two
Computers use binary numbers for internal storage of any data. A single binary digit is called a bit. Eight bit
together makes a byte.
Introduction to Computer Application, Pritom Paul, NEUB 2
Smaller Unit Larger Unit Symbol
8 Bits 1 Byte B
10
2 Bytes 1 Kilobytes KB
20
2 Bytes 1 Megabytes MB
230 Bytes 1 Gigabytes GB
40
2 Bytes 1 Terabytes TB
1.3.3. Octal Number System (Base 8)
• Uses digits 0 to 7.
• Convenient for representing large binary numbers in a compact form.
Example: 725₈
1.3.4. Hexadecimal Number System (Base 16)
• Uses digits 0-9 and letters A-F (A=10, B=11, … F=15).
• Compact representation of binary numbers.
Example: 2F₁₆
2. Number Conversion Techniques
2.1. General idea on ‘Decimal to Base B’ and ‘Base B to Decimal’
2.1.1. Decimal Integers to Base B:
Method:
• Repeatedly divide the integer by B.
• Collect remainders from last division (MSB) to first division (LSB).
Examples:
• Binary (Base 2): 4310 →1010112 (Remainders: 1, 1, 0, 1, 0, 1).
• Octal (Base 8): 13210 → 2048 (Remainders: 4, 0, 2).
• Hexadecimal (Base 16): 29110 →12316 (Remainders: 3, 2, 1).
2.1.2. Decimal Fractions to Base B:
Method:
• Repeatedly multiply the fraction by B.
• Collect integer parts from first multiplication (MSB) to last multiplication (LSB).
• Note: Some fractions may not terminate in the new base.
Example:
• Binary (Base 2): 0.37510 → 0.0112 (Integer parts: 0, 1, 1).
2.1.3. Conversion of Mixed Numbers (Integer + Fraction):
Method:
• Convert integer and fractional parts separately.
• Combine results.
2.1.4. Base B to Decimal
To convert a number of any base B to decimal all of the digits of the number are multiplied by their
positional value and then added, the sum is the equivalent decimal number.
2.2. Direct Conversion between Binary and Octal/Hexadecimal.
2.2.1. Binary to Octal (Direct Method)
1. Group binary digits in sets of 3 bits starting from the right (add leading 0s if needed).
2. Convert each group of 3 bits to its octal equivalent.
Introduction to Computer Application, Pritom Paul, NEUB 3
Example: Convert 11001002 (binary) to octal
Group: 001 100 100
Convert:
• 001 = 1
• 100 = 4
• 100 = 4
✅ Final Answer: 1448
2.2.2. Octal to Binary (Direct Method)
1. Convert each octal digit to 3-bit binary.
Example: Convert 2148 to binary
Convert:
• 2 = 010
• 1 = 001
• 4 = 100
✅ Final Answer: 0100011002
2.2.3. Binary to Hexadecimal (Direct Method)
1. Group binary digits in sets of 4 bits starting from the right (add leading 0s if needed).
2. Convert each 4-bit group to its hexadecimal equivalent.
Example: Convert 1101102 to hexadecimal
Group from right: 0011 0110 (added two leading 0s to make full 4-bit groups)
Convert:
• 0011 = 3
• 0110 = 6
✅ Final Answer: 3616
2.2.4. Hexadecimal to Binary (Direct Method)
1. Convert each hex digit into 4-bit binary.
Example: Convert 2F16 to binary
Convert:
2 = 0010
F = 1111
✅ Final Answer: 001011112
2.3. Conversion between Hexadecimal and Octal (via Binary)
2.3.1. Hexadecimal to Octal
Steps:
1. Convert each hex digit to 4-bit binary.
2. Group the binary digits into 3 bits from right (add leading 0s if needed).
3. Convert each 3-bit group to an octal digit.
Example: Convert 2F16 to octal
1. Hex to binary:
• 2 = 0010
• F = 1111
• Binary = 00101111
Introduction to Computer Application, Pritom Paul, NEUB 4
2. Group into 3 bits from right:
• 00 101 111 → add a leading 0 to make 3-bit groups: 000 101 111
3. Convert binary to octal:
• 000 = 0
• 101 = 5
• 111 = 7
4. ✅ Final Answer: 0578
2.3.2. Octal to Hexadecimal
Steps:
1. Convert each octal digit to 3-bit binary.
2. Group the binary digits into 4-bit sets from right (add leading 0s if needed).
3. Convert each 4-bit group to a hex digit.
Example: Convert 745 (octal) to hexadecimal
1. Octal to binary:
• 7 = 111
• 4 = 100
• 5 = 101
• Binary = 111100101
2. Group into 4 bits from right:
• Binary = 000111100101 (add leading 0s)
• Groups: 0001 1110 0101
3. Convert to hex:
• 0001 = 1
• 1110 = E
• 0101 = 5
4. ✅ Final Answer: 1E5 (hex)
3. Binary Addition and Binary Subtraction
3.1. Binary Addition
Basic Rules:
A B A+B Carry
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1 (carry)
1 1+1 1 (sum) 1 (carry) — because 1+1+1 = 11 (binary)
Example 1: 1011 + 1101
1011
+ 1101
-------------
11000 ← (result)
Introduction to Computer Application, Pritom Paul, NEUB 5
3.2. 1's Complement (One’s Complement)
Definition: 1's complement of a binary number is formed by flipping all the bits (change 0 → 1 and 1 → 0).
Example:
Original: 1010
1's complement: 0101 (just flip each bit)
3.3. 2's Complement (Two’s Complement)
Definition: 2's complement is obtained by adding 1 to the 1's complement of a binary number.
Steps:
1. Find the 1's complement
2. Add 1 to the result
Example:
Original: 1010
1. 1's complement: 0101
2. Add 1: 0101 + 0001 = 0110
✅ 2's complement: 0110
Why Use 2's Complement?
1. Computers use 2's complement to represent negative numbers.
2. It simplifies binary subtraction (we can add negative numbers instead of subtracting).
3. Only one zero (0000), unlike 1’s complement which has +0 and -0.
3.4. Binary Subtraction
Basic Rules:
A B A-B Borrow
0 0 0 0
1 0 1 0
1 1 0 0
0 1 1 1 (borrow from next digit)
Example 2: 1010 – 0011
1010
- 0011
---------
0111
3.4.1. Borrow Method
• This is similar to decimal subtraction.
• If a bit in the minuend (top number) is smaller than the subtrahend (bottom number), borrow 1 from
the next higher bit.
• After borrowing, subtract normally.
• Example:
1000
- 0011
--------
0101
Problems with borrow method:
• Complexity: Requires tracking borrows across bit positions, complicating hardware design.
Introduction to Computer Application, Pritom Paul, NEUB 6
• Performance: Slower due to sequential borrow propagation.
• Usage: Obsolete in modern digital systems.
3.4.2. 1’s Complement Method
• First, find the 1’s complement of the subtrahend (invert all bits).
• Add this complement to the minuend.
• If there is a carry, add it back to the result (this is called "end-around carry").
• If there is no carry, take the 1’s complement of the result and make it negative.
• Example:
Problems with 1’s complement method:
• Zero Representation: Has two representations for zero (+0 and –0), leading to ambiguity.
• Arithmetic Operations: Necessitates an end-around carry in addition, adding complexity.
• Usage: Rarely used in contemporary computing.
3.4.3. 2’s Complement Method
• Add leading zeros to make both binary numbers the same length.
• Take the 2’s complement of the number to be subtracted.
• Add it to the other number.
• If there is an overflow (extra bit in the sum), discard it—the result is positive.
• If there’s no overflow, the result is negative. Take the 2’s complement of the sum and attach a minus
sign.
• Example:
o Subtract 1100₂ from 10001₂ using 2’s complement method.
1100₂ → 1’s comp: 0011₂
→ 2’s comp: 0100₂
+10001₂
+ 0100₂
--------
1 01001₂ → overflow
Introduction to Computer Application, Pritom Paul, NEUB 7
o Subtract 1100₂ from 10001₂ using 2’s complement method.
01100
+ 01110
---------
11010 ← No overflow (no extra bit)
No overflow → Result is negative: Take 2’s complement of the result 11010:
- 1’s complement = 00101
- Add 1: 00101 + 1 = 00110
Attach minus sign
- Final answer: −00110₂
3.5. Octal Addition
Rules:
• Add digits as in decimal.
• If the sum is 8 or more, subtract 8 and carry 1 to the next higher position.
Example:
3.6. Hexadecimal Addition
Rules:
• Add as in decimal.
• If the sum is 16 or more, subtract 16 and carry 1.
• Use hexadecimal values (A-F) in the result as needed.
Examples:
4. Representation of Signed Numbers
❖ What is a signed number?
A number that can be positive or negative is called a signed number.
❖ Why do we need signed number representation in computers?
Computers store all data in binary (0s and 1s), and basic binary cannot differentiate between positive and
negative values without a scheme.
In binary representation, one bit is reserved for the sign: 0 → Positive and 1 → Negative.
For example, in an 8-bit/n-bit number machine, the most significant bit (MSB) is the sign bit.
Introduction to Computer Application, Pritom Paul, NEUB 8
4.1. Methods of Signed Number Representation
There are three ways to represent signed number,
1. Sign and Magnitude
2. 1’s Complement
3. 2’s Complement (Most widely used)
4.1.1. Sign and Magnitude
The MSB is the sign, the rest is magnitude.
Example (8 bits):
• +18 → 00010010
• −18 → 10010010
❖ Pros: Simple and intuitive.
❖ Cons: Two representations of zero (00000000 and 10000000), makes arithmetic harder.
4.1.2. 1’s Complement
To represent negative numbers: invert all bits (flip 0 to 1, and 1 to 0).
Example:
• +18 → 00010010
• −18 → invert → 11101101
❖ Pros: Simple to negate a number (just flip).
❖ Cons: Still has two representations of 0: 00000000 (+0) and 11111111 (−0).
4.1.3. 2’s Complement (Most widely used)
To find negative: 1’s complement + 1
Example:
• +18 → 00010010
• −18:
o Invert → 11101101
o Add 1 → 11101110
• Pros:
• Only one representation of zero.
• Simple binary addition and subtraction.
• No need to treat +ve and -ve separately in hardware.
4.1.4. Example Problem:
• Example 1: If 001011012 is in signed 2’s complement form, what is the represented decimal value?
Solution: As the leftmost bit is 0, the number is positive. The value of the number will be:
00101101
→ 0 + 0 + 1(×32) + 0 + 1(×8) + 1(×4) + 0 + 1(×2)
The represented value is,
32 + 8 + 4 + 1 = 4510
• Example 2: If 101011012 is in signed 2’s complement form, what is the represented decimal value?
Solution: As the leftmost bit is 1, the number is negative. The value of the number will be 2’s complement
of 101011012.
• Changing the bits, 1’s complement is 010100102;
• adding 1, we find the 2’s complement 010100112.
• The decimal value is:
Introduction to Computer Application, Pritom Paul, NEUB 9
01010011
→ 0 + 1 (×64) + 0 + 1(×16) + 0 + 0 + 1(×2) + 1(×1)
→ 64 + 16 + 2 + 1 = 8310
With attached minus sign, the answer is −8310.
5. Coding
Coding, in the context of digital systems, is the process of representing data—such as numbers, letters, or
symbols—as binary codes (sequences of 0s and 1s) that computers can understand and process.
5.1. Binary Coded Decimal (BCD)
Binary Coded Decimal (BCD) is a coding scheme used to represent decimal numbers in digital systems.
Unlike pure binary representation, which converts the entire decimal number into binary, BCD replaces each
individual digit of the decimal number with its 4-bit binary equivalent. This method is particularly useful in
systems where simplicity and direct digit manipulation are prioritized over computational efficiency.
BCD Representation:
Decimal Binary Decimal Binary
0 0000 5 0101
1 0001 6 0110
2 0010 7 0111
3 0011 8 1000
4 0100 9 1001
Why Use BCD?
While BCD requires more bits than pure binary representation, it offers advantages in certain applications:
• Simplicity: No complex conversions are needed; each digit is directly replaced by its 4-bit code.
• Accuracy: Avoids rounding errors that can occur in binary conversions.
• Ease of Display: Ideal for systems like calculators and digital clocks where each digit must be
displayed individually.
Disadvantage: BCD is less efficient in terms of storage and computation compared to pure binary.
5.1.1. Examples of BCD Conversion
❖ Example 1: Convert 25310 25310 to BCD.
Break down the decimal number into individual digits: 2, 5, 3.
Replace each digit with its 4-bit BCD code:
• 2 → 0010
• 5 → 0101
• 3 → 0011
Combine the codes: 25310 = 001001010011BCD.
❖ Example 2: Convert 100101110010BCD to Decimal.
Split the BCD code into groups of 4 bits: 1001, 0111, 0010.
Convert each group to its decimal equivalent:
• 1001 → 9
• 0111 → 7
• 0010 → 2
Combine the digits: 100101110010BCD = 97210.
5.1.2. Applications of BCD
BCD is commonly used in:
Introduction to Computer Application, Pritom Paul, NEUB 10
• Calculators: Simplifies digit-by-digit display and input.
• Digital Clocks: Each digit (hours, minutes, seconds) is handled separately.
• Financial Systems: Ensures precise decimal arithmetic without binary conversion errors.
5.2. ASCII (American Standard Code for Information Interchange)
ASCII is a character encoding standard used to represent text in computers and communication devices. It
assigns a unique 7-bit binary number (0-127) to each character, including letters, digits, punctuation, and
control codes. Developed in the 1960s by the American National Standards Institute (ANSI).
5.2.1. ASCII Table Structure
➢ Total Characters: 128 (0 to 127 in decimal).
➢ Divided into two parts:
o Non-Printable (Control Characters, 0-31 & 127)
▪ Used for device control (e.g., NULL, ESC, DEL, TAB, ENTER).
o Printable Characters (32-126)
o Includes:
▪ Digits (0-9): 48 to 57.
▪ Uppercase Letters (A-Z): 65 to 90.
▪ Lowercase Letters (a-z): 97 to 122.
▪ Punctuation/Symbols: e.g., !, @, #, $, etc.
5.2.2. Extended ASCII (8-bit)
• Standard ASCII uses 7 bits, but computers use 8-bit bytes.
• Extended ASCII (128-255) includes additional symbols, accented letters, and graphics.
• Not standardized; varies by system (e.g., ISO-8859-1, Windows-1252).
5.2.3. Applications
• Text Files: Storing letters, numbers, and symbols.
• Networking: Data transmission (e.g., HTTP, FTP).
• Programming: Strings and character handling in code.
• Keyboard Input: Each key press sends an ASCII code to the computer.
5.2.4. Limitations
Limited to English: No support for non-Latin scripts (e.g., Chinese, Arabic).
5.3. EBCDIC (Extended Binary Coded Decimal Interchange Code)
EBCDIC is an 8-bit character encoding developed by IBM in the 1960s for mainframe computers. Unlike
ASCII, it is based on Binary Coded Decimal (BCD) principles. Primarily used in IBM mainframes (e.g.,
z/OS) and legacy systems.
5.3.1. Key Features
• 8-Bit Encoding: Represents 256 possible characters (0-255).
• Non-Contiguous Alphabets: Letters (A-Z, a-z) are not in sequential order, unlike ASCII.
• Multiple Variants: Different code pages (e.g., EBCDIC 037 for US English, EBCDIC 500 for
international).
Example:
Range (Hex) Characters
00-3F Control characters (e.g., NUL, LF)
40-5A Special symbols (e.g., @, #, $)
81-A9 Uppercase letters (A-Z)
C1-E9 Lowercase letters (a-z)
F0-F9 Digits (0-9)
Introduction to Computer Application, Pritom Paul, NEUB 11
5.3.2. Applications
• IBM Mainframes: z/OS, AS/400 systems.
• Legacy Databases: Banking, airline reservations.
• File Transfers: Requires conversion to/from ASCII for compatibility.
5.3.3. Limitations
• Complexity: Non-sequential letters complicate programming.
• Obsolescence: Replaced by ASCII/Unicode in modern systems.
• Limited Support: Rarely used outside IBM ecosystems.
5.4. Unicode
Unicode is a universal character encoding standard designed to represent text from all writing systems
worldwide. It is maintained by: The Unicode Consortium (a nonprofit organization).
5.4.1. Key Features
• Bit Capacity:
o Originally a 16-bit system, allowing for 216=65,536 possible symbols.
• ASCII Compatibility:
o The first 128 codes are identical to ASCII, ensuring backward compatibility.
• Language Support:
o Includes scripts like Bengali (assigned hex range 0980–09FF), along with Latin, Cyrillic, Arabic, etc.
5.4.2. Modern Context
• Usage: Dominates modern computing (web, OS, programming).
• Encoding Schemes: UTF-8 (variable-width), UTF-16 (fixed 2/4 bytes), and UTF-32 (fixed 4 bytes).
• Updates: Continuously expanded to include emoji, ancient scripts, and specialized symbols.