0% found this document useful (0 votes)
3 views10 pages

Introduction To CS Notes

The document provides an introduction to computer science, focusing on number systems including binary, decimal, octal, and hexadecimal. It explains the conversion methods between these systems, the significance of binary in computing, and details about ASCII and Binary Coded Decimal (BCD). Additionally, it covers 1's and 2's complement subtraction methods with examples.

Uploaded by

cj686528
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views10 pages

Introduction To CS Notes

The document provides an introduction to computer science, focusing on number systems including binary, decimal, octal, and hexadecimal. It explains the conversion methods between these systems, the significance of binary in computing, and details about ASCII and Binary Coded Decimal (BCD). Additionally, it covers 1's and 2's complement subtraction methods with examples.

Uploaded by

cj686528
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Introduction to Computer Science - Student Notes

Introduction to Computer Science:


Computer Science is the study of computers, their components, programming, and applications. It
involves understanding how computers work, how to give instructions (programming), and how they
solve problems efficiently.

Number System

A Number System is a method of representing numbers using a set of symbols (digits) according to
certain rules.
Radix (Base)
The radix or base of a number system is the total number of unique digits, including zero, used in
that system.
Binary Number System – Definition
The Binary Number System is a method of representing numbers using only two symbols: 0 and 1.
It has a base of 2, meaning each position (bit) represents a power of 2. This system is used in
computers because digital circuits recognize two states: ON (1) and OFF (0).
Advantages of Binary Code
Simplicity of Design
Binary uses only two symbols: 0 and 1.
Easy to represent using electrical signals (ON = 1, OFF = 0).
Reliability in Digital Systems
Less chance of error because only two states are used.
Works well in noisy environments.
Compatibility with Logic Gates
Computers use logic gates (AND, OR, NOT) which work naturally with binary values.
Efficient Data Processing
All types of data (numbers, text, images, audio) can be converted into binary.
Storage and Memory Optimization
Binary makes it simple to store and retrieve data in electronic devices.
Radix (Base) – Definition
The radix (or base) of a number system is the total number of unique digits, including zero, used to
represent numbers in that system.
Explanation
Determines how many symbols are used in a number system.
Positional value of digits is calculated using powers of the radix
Examples
Binary System – Radix 2
Digits: 0, 1
Decimal System – Radix 10
Digits: 0 to 9
Octal System – Radix 8
Digits: 0 to 7
Hexadecimal System – Radix 16
Digits: 0–9 and A–F
What is Binary Counting?
Binary uses only 0 and 1 to count numbers.
It is like decimal counting, but instead of 10 digits (0–9), we only have 2 digits (0 and 1).
When we reach 1, the next number becomes 10 (just like after 9 in decimal, we write 10).
How Counting Works
Decimal counting: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11...
Binary counting: 0, 1, 10, 11, 100, 101, 110, 111, 1000...

1.2 Binary to Decimal Conversion

Definition
Binary to decimal conversion is the process of changing a number from the binary system (base 2)
to the decimal system (base 10).
Method
Write down the binary number.
Multiply each digit by 2■ where n is the position of the digit from the right (starting from 0).
Add all the results to get the decimal number.
For Fractional Part
Start from the first digit after the decimal point.
Assign negative powers of 2 (2^−1,2^−2,2^−3,…2^{-1}, 2^{-2}, 2^{-3},..)
Multiply each binary digit by its power of 2.
Add them to get the fractional decimal value.
1. Binary → Octal (Base 2 → Base 8)
Since 8=238 = 2^38=23, we group binary digits into 3 bits.
Integer Part
Group binary digits into 3 bits from the right.
Add leading zeros if necessary to complete the last group.
Replace each 3-bit group with its octal equivalent.
Fractional Part
Group binary digits into 3 bits from the left (after the binary point).
Add trailing zeros if necessary to complete the last group.
Replace each 3-bit group with its octal equivalent.
2. Binary → Hexadecimal (Base 2 → Base 16)
Since 16=2416 = 2^416=24, we group binary digits into 4 bits.
Integer Part
Group binary digits into 4 bits from the right.
Add leading zeros if necessary to complete the last group.
Replace each 4-bit group with its hexadecimal equivalent (0–9, A–F).
Fractional Part
Group binary digits into 4 bits from the left (after the binary point).
Add trailing zeros if necessary to complete the last group.
Replace each 4-bit group with its hexadecimal equivalent (0–9, A–F).
Decimal Number System (Base 10)
Definition
The decimal number system is the standard system we use in daily life. It has base (radix) 10 and
uses ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
Features
Each digit’s value depends on its position (place value).
Position values are powers of 10 (… 10³, 10², 10¹, 10■).
Widely used in arithmetic, finance, and everyday calculations

Steps for Decimal → Binary Conversion

For Integer Part


Divide the decimal number by 2.
Write down the remainder (0 or 1).
Repeat the process with the quotient until it becomes 0.
Read the remainders from bottom to top → gives binary number.
For Fractional Part
Multiply the fractional part by 2.
Record the integer part (0 or 1).
Repeat the process with the fractional result until it becomes 0 (or desired accuracy).
Read the digits from top to down → gives binary fraction.
Decimal → Octal (Steps)
Integer Part
Divide the decimal number by 8.
Write the remainder.
Repeat until quotient = 0.
Read remainders bottom → top.
Fractional Part
Multiply the fraction by 8.
Write the integer part.
Repeat with the new fraction.
Read digits top → down.
Decimal → Hexadecimal (Steps)
Integer Part
Divide the decimal number by 16.
Write the remainder (0–9, A–F).
Repeat until quotient = 0.
Read remainders bottom → top.
Fractional Part
Multiply the fraction by 16.
Write the integer part (0–9, A–F).
Repeat with the new fraction.
Read digits top → down.
Hexadecimal Number System (Base 16)

Hexadecimal Number System

The Hexadecimal Number System is a positional number system with base 16.
It uses 16 symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Here:
A = 10, B = 11, C = 12, D = 13, E = 14, F = 15 (in decimal).
Place Values
Each position in a hexadecimal number represents a power of 16.
Rightmost digit → 160
Next digit → 161
Next digit → 162, and so on.
Relation with Binary
1 hexadecimal digit = 4 binary bits (nibble)
Example:
A (hex) = 1010 (binary)
F (hex) = 1111 (binary)
Uses of Hexadecimal
Short and compact representation of long binary numbers.
Widely used in:
Programming and debugging
Computer memory addressing
Color codes in HTML/CSS (e.g., #FF5733)

Hexadecimal to Binary Conversion

Integer Part
Write down the hexadecimal number.
Replace each hex digit with its 4-bit binary equivalent.
Arrange the groups in the same order (left to right).
Remove any leading zeros (if needed).
Fractional Part
Write down the hexadecimal fraction.
Replace each hex digit after the decimal point with its 4-bit binary equivalent.
Arrange the groups in the same order (after the binary point).
Do not drop trailing zeros unless simplification is required.
Hexadecimal to Decimal Conversion

Integer Part
Write the hexadecimal number.
Starting from the rightmost digit, multiply each digit by 16position16^{position}16position, where
position = 0,1,2,…
Add all the products together.
The result is the decimal value.
Fractional Part
Write the hexadecimal fraction.
Starting from the first digit after the decimal point, multiply each digit by
16−position16^{-position}16−position, where position = 1,2,3,…
Add all the products together.
The result is the decimal fractional value.
Final Decimal Number = (Sum of Integer Part) + (Sum of Fractional Part)

Hexadecimal to Octal Conversion

Since hexadecimal (base 16) and octal (base 8) are not direct multiples, we usually convert via
binary as an intermediate step.
Integer Part
Write the hexadecimal number.
Convert each hex digit into its 4-bit binary equivalent.
Group the binary digits into 3-bit groups (from right to left).
Replace each 3-bit group with its octal equivalent.
Write the octal digits in the same order (remove any leading zeros).
Fractional Part
Write the hexadecimal fraction.
Convert each hex digit into its 4-bit binary equivalent.
Group the binary digits into 3-bit groups (from left to right after the binary point).
Replace each 3-bit group with its octal equivalent.
Write the octal digits in the same order (remove any trailing zeros if needed).
Rule Summary: Hex → Binary (4 bits each) → Group into 3 bits → Octal.

Octal Number System

The Octal Number System is a positional number system with base 8.


It uses 8 digits only: 0, 1, 2, 3, 4, 5, 6, 7
Place Values
Each position in an octal number represents a power of 8.
Rightmost digit → 808^080
Next digit → 818^181
Next digit → 828^282, and so on.
Relation with Binary
1 octal digit = 3 binary bits
Example:
(7)■ = (111)■
(5)■ = (101)■
Uses of Octal
Short representation of long binary numbers.
Used in:
Computer systems (especially older ones).
Digital electronics.
File permissions in UNIX/Linux (e.g., chmod 755).
1. Octal → Binary
Since 8=238 = 2^38=23, each octal digit is directly replaced by 3 binary bits.
Integer Part
Write the octal number.
Replace each octal digit with its 3-bit binary equivalent.
Arrange groups in the same order (remove extra leading zeros if needed).
Fractional Part
Write the octal fraction.
Replace each octal digit (after the decimal) with its 3-bit binary equivalent.
Arrange groups in the same order (remove trailing zeros if needed).
2. Octal → Decimal
Integer Part
Write the octal number.
Starting from the rightmost digit, multiply each digit by 8position8^{position}8position, where
position = 0,1,2,…
Add all the products.
Fractional Part
Write the octal fraction.
Starting from the first digit after the decimal point, multiply each digit by
8−position8^{-position}8−position, where position = 1,2,3,…
Add all the products.
■ Final Decimal Number = (Integer part sum) + (Fractional part sum)
3. Octal → Hexadecimal
Since octal (base 8) and hexadecimal (base 16) are not direct multiples, we convert via binary.
Integer Part
Convert the octal number → binary (3 bits per digit).
Group binary digits into 4 bits from the right.
Replace each 4-bit group with its hex equivalent (0–9, A–F).
Fractional Part
Convert the octal fraction → binary (3 bits per digit).
Group binary digits into 4 bits from the left (after decimal).
Replace each 4-bit group with its hex equivalent (0–9, A–F).
Binary Coded Decimal (BCD)
Definition
BCD (Binary Coded Decimal) is a number system where each decimal digit (0–9) is represented by
its 4-bit binary equivalent.
It is not a separate base system like binary, octal, or hex, but a way of encoding decimal numbers in
binary form.
BCD Representation
Each decimal digit (0–9) is written in binary (4 bits).
Example mapping:
0 → 0000
1 → 0001
2 → 0010
3 → 0011
4 → 0100
5 → 0101
6 → 0110
7 → 0111
8 → 1000
9 → 1001
Only 0000 to 1001 are valid BCD codes (1010–1111 are unused).
ASCII (American Standard Code for Information Interchange)
1. What is ASCII?
ASCII is a code used by computers to represent text characters (letters, numbers, symbols, control
keys) in binary form.
Every character (like A, 5, @, space, etc.) is given a unique number.
That number is then stored inside the computer in binary (0s and 1s).
2. How many characters?
ASCII uses 7 bits → this gives 128 codes (from 0 to 127 in decimal).
Later, an 8-bit extended ASCII was introduced (0–255) for more symbols.
3. ASCII Code Groups
0–31 → Control characters (not printed, used for actions like Enter, Tab, Bell).
32–126 → Printable characters (letters, numbers, punctuation, space).
127 → Delete (DEL).
4. Examples
So, when you type A, the computer actually stores 1000001 (binary for 65).
5. Why is ASCII important?
It became the first standard way to exchange text between computers.
Ensures that the same binary code means the same character on every machine.
Used in early programming, data transfer, and internet protocols.
Basis for modern character sets (Unicode is built on ASCII).
1’s-complement and 2’s-complement subtraction — detailed rules + examples
Preliminaries / rules used in examples
Use a fixed n-bit width for both numbers (all examples below use 5 bits) — you must use the same
width for minuend and subtrahend.
Always write both numbers in that n-bit form before starting (add leading zeros if needed).
Decimal checks are shown to verify correctness.
A. 1’s-complement subtraction
Rule (integer subtraction A − B):
Represent A and B in n bits.
Find 1’s complement of B (flip every bit: 0→1, 1→0).
Add that 1’s-complement of B to A (binary addition).
If there is a carry out from the MSB (an extra leftmost 1), add that carry (1) to the LSB of the result
— this is called end-around carry. The final result (after adding end-around carry) is the correct
positive difference.
If there is no carry out, the result is negative. To get its magnitude: take the 1’s complement of the
sum and put a negative sign.
Example 1 (positive result)
Compute: 101012−00111210101_2 - 00111_2101012■−001112■ (5-bit)
Decimal check: 21 − 7 = 14.
Steps:

A = 10101 (21). B = 00111 (7).

1’s complement of B = flip 00111 → 11000.


Add:
10101
+ 11000
=1 01101 ← there is a carry out (leftmost 1)
Drop the leftmost carry and perform end-around carry: result without carry = 01101. Add the carry 1
to LSB:
01101
+ 00001
= 01110
01110 = 14 → matches 21 − 7 = 14. ■
Example 2 (negative result)
Compute: 001112−10101200111_2 - 10101_2001112■−101012■ (5-bit)
Decimal: 7 − 21 = −14
Steps:

A = 00111 (7). B = 10101 (21).

1’s complement of B = flip 10101 → 01010.


Add:
00111
+ 01010
= 10001 ← no carry out
No carry → result is negative. Take 1’s complement of 10001:
1’s complement of 10001 → 01110 (decimal 14).
Answer = −01110 → −14. ■
Notes (1’s-complement):
Two zeros exist (all zeros = +0, all ones = −0) in pure 1’s complement systems — awkward, which
is why 2’s complement is preferred in practice.
Use end-around carry only when there is a carry out.
B. 2’s-complement subtraction
Rule (integer subtraction A − B):
Represent A and B in n bits.
Find 2’s complement of B: invert bits (1’s complement) then add 1. This gives the binary for (−B) in
2’s-complement arithmetic (within the chosen width).
Add A and 2’s complement of B.
If there is a carry out (an extra leftmost 1), discard that carry — the remaining n bits are the correct
positive result.
If there is no carry out, the n-bit result is negative in 2’s-complement form. To find magnitude, take
the 2’s complement of that result and add a negative sign.
Why 2’s complement is preferred: unique zero, simpler hardware (no end-around carry),
straightforward sign representation.
Example 3 (positive result) — same numbers as earlier
Compute: 101012−00111210101_2 - 00111_2101012■−001112■ (5-bit)
Decimal check: 21 − 7 = 14.
Steps:

A = 10101. B = 00111.

2’s complement of B:
invert 00111 → 11000
add 1 → 11001 (this is 2’s complement of 7)
Add:
10101
+ 11001
=1 01110 ← carry out = 1
Discard carry out → result 01110 (14). ■
Example 4 (negative result)
Compute: 001112−10101200111_2 - 10101_2001112■−101012■ (5-bit)
Decimal: 7 − 21 = −14
Steps:

A = 00111. B = 10101.

2’s complement of B:
invert 10101 → 01010
add 1 → 01011
Add:
00111
+ 01011
= 10010 ← no carry out
No carry out → result 10010 is negative (2’s complement form). To get magnitude:
take 2’s complement of 10010: invert → 01101, add 1 → 01110 (14).
Answer = −01110 = −14. ■
Notes (2’s-complement):
Single representation of zero (good).
Hardware uses same adder for addition and subtraction (just invert and add 1 for subtrahend).
If working in fixed n bits, be mindful of overflow: if the true mathematical result is outside
representable range for n bits, you get overflow. For signed numbers, overflow detection rules differ
(but for classroom problems with small numbers, choose n large enough).
Quick summary — HOW TO DO subtraction using complements (cheat-sheet)
1’s complement method (n bits):
1’s-complement(B) → add to A.
If carry out → add 1 (end-around carry) → positive result.
If no carry → 1’s-complement(sum) and mark negative.
2’s complement method (n bits):
2’s-complement(B) = invert(B) + 1 → add to A.
If carry out → discard it → positive result.
If no carry → result is negative in 2’s-complement; take 2’s-complement to get magnitude and put
minus sign.

■ Practice Corner
1. Convert (101101)■ into Octal and Hexadecimal. 2. Convert (3F)■■ into Binary and Decimal. 3.
Find the 1’s and 2’s complement of (11010)■. 4. Represent the decimal number 47 in BCD. 5.
State any three advantages of the Binary Number System.

You might also like