Cs Book
Cs Book
A floating point number represents real numbers using scientific notation in binary format.
Is the Bias Always 127? No. The bias value depends on the precision format being used in IEEE 754
standard:
This bias helps in representing both positive and negative exponents without using a sign bit for the
exponent itself.
Why Add 127 (Bias) to the Exponent? In IEEE 754 format, the exponent is stored using a technique called
"biased exponent." This means: - Instead of storing negative exponents directly (which would require a
separate sign), we add a constant value (called bias) to the actual exponent. - For 32-bit IEEE 754, the bias is
127. - So, an actual exponent of 0 is stored as 127, exponent 1 as 128, exponent -1 as 126, etc. - This
simplifies hardware implementation and comparison of floating point numbers.
IEEE 754 Single Precision Format (32-bit): - 1 bit for Sign (0 = positive, 1 = negative) - 8 bits for Exponent
(with a bias of 127) - 23 bits for Mantissa (fractional part after the leading 1)
Steps: 1. Convert the number to binary. 2. Normalize it (shift to make only one non-zero digit before
decimal). 3. Determine sign bit (0 or 1). 4. Calculate exponent and add bias. 5. Write the mantissa.
Example: Represent 5.75 in IEEE 754: - Binary of 5.75 = 101.11 - Normalized: 1.0111 × 2² - Sign = 0 (positive)
- Exponent = 2 + 127 = 129 → 10000001 - Mantissa = 01110000000000000000000 - Result: 0 10000001
01110000000000000000000
Operations:
1
Complements:
• 1’s Complement:
• Flip all bits (0↔1)
• 2’s Complement:
1.5 Codes
1. BCD (Binary-Coded Decimal): - Each digit of a decimal number is represented by its 4-bit binary
equivalent. - Example: - Decimal 259 → BCD: 0010 0101 1001 - Used in digital clocks, calculators.
2. Excess-3 (XS-3): - A self-complementary code used for decimal digits. - It adds 3 to each decimal digit,
then converts to binary. - Example: - Decimal 4 → 4 + 3 = 7 → Binary: 0111
3. Gray Code: - Gray Code is a binary numbering system where only one bit changes at a time between
two successive numbers. - This helps prevent errors in digital electronics, especially during signal transition
when multiple bits changing simultaneously might cause glitches.
• When binary numbers count up (e.g., from 3 (011) to 4 (100)), more than one bit changes at once.
• This can confuse digital circuits if bits change at slightly different times.
• Gray Code prevents this by ensuring only one bit flips at a time.
• Binary = 1 0 1 1
• Step 1: First bit = 1
• Step 2: 1 ⊕ 0 = 1
• Step 3: 0 ⊕ 1 = 1
• Step 4: 1 ⊕ 1 = 0
• Gray Code = 1 1 1 0
2
Another Example: Convert Binary 1101 to Gray Code
• Binary = 1 1 0 1
• Step 1: First bit = 1
• Step 2: 1 ⊕ 1 = 0
• Step 3: 1 ⊕ 0 = 1
• Step 4: 0 ⊕ 1 = 1
• Gray Code = 1 0 1 1
To convert Gray Code back to Binary: 1. Keep the first bit (MSB) the same. 2. For each next bit: - If Gray bit =
0 → Copy previous binary bit - If Gray bit = 1 → Invert previous binary bit
• Gray = 1 0 1 1
• Step 1: First bit = 1
• Step 2: 0 → Copy = 1
• Step 3: 1 → Invert = 0
• Step 4: 1 → Invert = 1
• Binary = 1 1 0 1
• Rotary Encoders
• Karnaugh Maps (to reduce logic expressions)
• Analog-to-Digital Conversion
4. ASCII (American Standard Code for Information Interchange): - 7-bit code to represent text
characters. - Example: - A → 1000001 (65 in decimal), a → 1100001 (97 in decimal) - Used in keyboards, files,
text data.
5. EBCDIC (Extended Binary Coded Decimal Interchange Code): - 8-bit code used in IBM mainframes. -
Different from ASCII. - Example: - A → 11000001
Comparison Table:
3
Code Description Example
Logic gates are the fundamental building blocks of digital circuits. They perform basic logical functions
using binary input (0 and 1) and produce a single binary output.
AND A·B Output is 1 if both A and B are 1 0,0 → 0; 0,1 → 0; 1,0 → 0; 1,1 → 1
Each gate can be constructed using electronic components like diodes and transistors and is essential in
designing circuits.
Boolean algebra deals with expressions involving binary variables and logic operations.
Example: - Expression: Y = A·(B + ¬C) - Truth table involves listing all combinations of inputs A, B, and C, and
computing Y for each.
A B C ¬C B + ¬C A·(B + ¬C) = Y
0 0 0 1 1 0
0 0 1 0 0 0
1 1 0 1 1 1
4
A B C ¬C B + ¬C A·(B + ¬C) = Y
1 1 1 0 1 1