Learning Objectives
By the end of this lesson, you will be able to:
- Show understanding of and perform binary shifts: logical, arithmetic & cyclic
- Understand left shift and right shift operations
- Apply bitwise operations (AND, OR, XOR) for checking, setting, and clearing bits
- Use bit masking to control devices in monitoring and control systems
- Write assembly language instructions for bit manipulation (LSL, LSR)
- Trace bitwise operations and predict results
- Understand how each bit in a register can be used as a flag in control systems
Key Terms
Bit Manipulation
Operations that work on individual bits within binary values
Binary Shift
Moving bits stored in a register a given number of places within the register
Logical Shift
Bits shifted out of register are replaced with zeros
Arithmetic Shift
Sign of number is preserved during shift operations
Cyclic Shift
No bits are lost during a shift; bits shifted out are introduced at the other end
Bit Masking
Using a mask with logical operators to identify, remove or set a single bit or group of bits
AND Operation
Bitwise operation used to check if a bit has been set
OR Operation
Bitwise operation used to set a bit to 1
XOR Operation
Bitwise operation used to clear a bit that has been set
LSL (Logical Shift Left)
Assembly instruction to shift bits logically n places to the left
LSR (Logical Shift Right)
Assembly instruction to shift bits logically n places to the right
Flag
Individual bit in a register used to represent status or condition
Bit Manipulation Fundamentals
Bit manipulation involves working with individual bits within binary values. These operations are fast, simple, and essential for low-level programming and hardware control.
Assembly Language Bit Operations
| Label | Instruction | Explanation |
|---|---|---|
| AND #n / Bn / £n | Bitwise AND operation of the contents of ACC with the operand | |
| AND <address> | Bitwise AND operation of the contents of ACC with the contents of <address> | |
| XOR #n / Bn / £n | Bitwise XOR operation of the contents of ACC with the operand | |
| XOR <address> | Bitwise XOR operation of the contents of ACC with the contents of <address> | |
| OR #n / Bn / £n | Bitwise OR operation of the contents of ACC with the operand | |
| OR <address> | Bitwise OR operation of the contents of ACC with the contents of <address> | |
| LSL #n | Bits in ACC are shifted logically n places to the left. Zeros are introduced on the right hand end | |
| LSR #n | Bits in ACC are shifted logically n places to the right. Zeros are introduced on the left hand end | |
| <Label>: | <opcode> <operand> | Labels an instruction |
| <Label>: | <data> | Gives a symbolic address <label> to the memory location with contents <data> |
Notation Explained
ACC denotes Accumulator, IX denotes Index Register, # denotes a denary number (e.g. #123), B denotes a binary number (e.g. B01001010), & denotes a hexadecimal number (e.g. &4)
Bit Manipulation to Control Devices
Bit Masking
- Allows checking, setting and resetting individual bits within a binary value
- Bitwise operations are fast and simple operations on binary data
- Each binary digit is treated individually
- Advantage: speeds up processing and requires reduced processing
Applications
- Useful in simple control systems where individual bits are used as flags
- Substantial processing efficiency can be gained
- Widely used in networking when using subnet masks
- A mask is a number used with logical operators to identify, remove or set bits
Real-Life Example: Home Security System
Think of an 8-bit register controlling a home security system:
Bit Assignments:
- Bit 0: Front door sensor (1 = open, 0 = closed)
- Bit 1: Back door sensor
- Bit 2: Window sensor
- Bit 3: Motion detector
- Bit 4: Alarm armed status
- Bit 5: System power
- Bit 6: Notification enabled
- Bit 7: Battery status
Operations:
Activity 1: Understanding Bit Operations
For each scenario below, identify which bitwise operation (AND, OR, XOR) would be most appropriate:
- You need to check if Bit 3 (position 3) in an 8-bit register is set to 1
- You want to set Bit 5 (position 5) to 1 without affecting other bits
- You need to toggle Bit 0 (position 0) from 0 to 1 or 1 to 0
- You want to clear Bit 2 (position 2) that was previously set to 1
- You need to extract only the lower 4 bits of a byte (ignore the upper 4 bits)
Solution:
- AND operation - Use AND with a mask that has 1 only at Bit 3 (e.g., AND #B00001000). If result is non-zero, bit was set.
- OR operation - Use OR with a mask that has 1 at Bit 5 (e.g., OR #B00100000). Other bits remain unchanged.
- XOR operation - Use XOR with a mask that has 1 at Bit 0 (e.g., XOR #B00000001). Toggles 0→1 or 1→0.
- XOR operation - Use XOR with a mask that has 1 at Bit 2 (e.g., XOR #B00000100). Clears a set bit.
- AND operation - Use AND with mask #B00001111. Upper 4 bits become 0, lower 4 bits preserved.
Check Your Understanding: Bit Fundamentals
1. What is the main advantage of using bit masking? [2 marks]
Answer
- [1 mark] Speed up processing by performing operations directly on binary data
- [1 mark] Requires reduced or less processing to perform tasks as it requires just few binary tricks
- [Additional] Simple and efficient way to control individual bits without affecting others
2. What does the LSL instruction do in assembly language? [2 marks]
Answer
- [1 mark] Bits in the accumulator (ACC) are shifted logically n places to the left
- [1 mark] Zeros are introduced on the right-hand end of the register
- [Additional] The instruction format is LSL #n where n specifies how many places to shift
3. Give two applications of bit masking. [2 marks]
Answer
- [1 mark] Useful in simple control systems where individual bits are used as flags
- [1 mark] Widely used in networking when using subnet masks
- [Additional] Also used in graphics programming, embedded systems, and device drivers
4. What is the difference between AND #n and AND <address>? [2 marks]
Answer
- [1 mark] AND #n performs bitwise AND with an immediate value (the number n itself)
- [1 mark] AND <address> performs bitwise AND with the contents of a memory location
- [Additional] The first uses the value directly, the second fetches the value from memory first
5. Why are bitwise operations described as "fast and simple"? [2 marks]
Answer
- [1 mark] They work directly on binary data at the hardware level
- [1 mark] Each binary digit is treated individually, making operations predictable and efficient
- [Additional] Processors have built-in circuitry for these operations, making them execute in a single clock cycle
Monitoring and Control Systems
In monitoring and control systems, each bit in a register can be used as a flag to represent the status of different sensors or devices. Bitwise operations allow us to efficiently manage these flags.
Bitwise Operations in Control Systems
Find the value of a bit (AND operation)
Set the bit/bits to 1 (OR operation)
Set the bit/bits to 0 (XOR operation)
Set a bit/bits to the binary opposite (XOR operation)
Bitwise AND
Used to check if a bit has been set. If you AND a value with a mask containing 1 at the target bit position, the result will be non-zero if the bit was set.
Check if bit 2 is set: AND #B00000100
Bitwise OR
Used to set a bit to 1. If you OR a value with a mask containing 1 at the target position, that bit becomes 1 regardless of its previous value.
Set bit 3 to 1: OR #B00001000
Bitwise XOR
Used to clear a bit that has been set. If you XOR a value with a mask containing 1 at the target position, that bit toggles (0→1 or 1→0).
Clear bit 1: XOR #B00000010
Real-Life Example: Factory Control System
Imagine a factory with 8 machines. Each bit in an 8-bit register represents whether a machine needs maintenance:
Register: 01100101
Machines 1, 2, 5, 8 need maintenance (bits at positions 7, 6, 2, 0)
Operations:
AND #B00100000 → Result 0 → No maintenance needed
OR #B00010000 → Bit 4 becomes 1
XOR #B01000000 → Bit 6 toggles from 1 to 0
Assembly Language Examples
Setting All Bits To Zero
Loads byte from address 0034, uses AND with all zeros to convert each bit to 0, stores back.
Toggling One Bit
Toggles value of bit in position 0 (LSB) using XOR with mask 00000001.
Setting One Bit to 1
Sets flag represented by bit in position 2 to 1. All other bits remain unchanged.
Interactive Bit Manipulation Simulator
Experiment with bitwise operations on an 8-bit register. Try different masks and see the results:
Initial Register Value
Operation & Mask
Result
Perform an operation to see the result...
Activity 2: Control System Programming
A temperature monitoring system uses an 8-bit register where each bit represents a different sensor (bit 0 = sensor 1, bit 1 = sensor 2, etc.). Write assembly code to perform the following tasks:
- Check if sensor 3 (bit 2) has detected overheating (bit = 1)
- Set sensor 5 (bit 4) to indicate it needs calibration
- Toggle the alarm status (bit 7) to opposite of current state
- Clear the maintenance flag for sensor 2 (bit 1)
- Reset all sensors to 0 (normal state)
Solution:
1. Check sensor 3:
2. Set sensor 5 calibration flag:
3. Toggle alarm status:
4. Clear sensor 2 maintenance flag:
5. Reset all sensors:
Check Your Understanding: Monitoring & Control
1. In a control system with eight different sensors, how would you use a register to track which sensors have been processed? [3 marks]
Answer
- [1 mark] Use an 8-bit register where each bit represents one sensor
- [1 mark] When a sensor's data is processed, set its corresponding bit to 1
- [1 mark] Use AND to check if a bit has been set, OR to set a bit, XOR to clear a bit
- [Additional] This provides an efficient way to track multiple status flags in a single byte
2. What assembly code would toggle the value of bit stored in position 0? [2 marks]
Answer
Explanation: XOR with mask 00000001 toggles bit 0 (0→1 or 1→0) while leaving other bits unchanged.
3. How would you set a flag represented by bit in position 2 to value 1 without affecting other bits? [2 marks]
Answer
Explanation: OR with mask 00000100 sets bit 2 to 1 regardless of its previous value. Other bits remain unchanged because OR with 0 leaves them as they were.
4. What is the purpose of using AND #B00000010 to leave value in position 1 unchanged but convert every other bit to 0? [2 marks]
Answer
- [1 mark] To isolate and examine the value of a specific bit (bit 1 in this case)
- [1 mark] This technique extracts a single bit's value by clearing all other bits to 0
- [Additional] After this operation, the accumulator will be 0 if bit 1 was 0, or 2 (00000010) if bit 1 was 1
5. Why is XOR used to clear a bit that has been set, rather than AND? [3 marks]
Answer
- [1 mark] XOR toggles a bit: 0→1 or 1→0
- [1 mark] If you know a bit is set (1), XOR with 1 will clear it (1→0)
- [1 mark] AND could also clear a bit (AND with 0 at that position), but would require knowing the exact current state of other bits to preserve them
- [Additional] XOR with mask 1 at target position is simpler when you want to toggle or clear a specific known bit
Binary Shifts
Binary shift involves moving bits stored in a register a given number of places within the register. Each bit within register may be used for a different purpose.
Types of Binary Shifts
Logical Shift
Bits shifted out of register are replaced with zeros. Used for unsigned numbers.
Left Logical Shift
Moves each bit to left by one. Vacant least significant bit (LSB) is filled with zero and most significant bit (MSB) is discarded.
| MSB | Left Logical Shift | LSB | |||||
|---|---|---|---|---|---|---|---|
| 1 | 0 | 1 | 1 | 0 | 0 | 1 | 0 |
| → | Shift left 1 position | ||||||
| 0 | 1 | 1 | 0 | 0 | 1 | 0 | 0 |
MSB (1) discarded, LSB filled with 0. Effectively multiplies by 2 for each shift.
Right Logical Shift
Moves each bit to the right by one. Least significant bit is discarded and vacant MSB is filled with zero.
| MSB | Right Logical Shift | LSB | |||||
|---|---|---|---|---|---|---|---|
| 1 | 0 | 1 | 1 | 0 | 0 | 1 | 0 |
| → | Shift right 1 position | ||||||
| 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1 |
LSB (0) discarded, MSB filled with 0. Effectively divides by 2 for each shift (integer division).
Arithmetic Shift
Sign of number is preserved. Used for signed numbers (two's complement).
Right Arithmetic Shift
Moves each bit to right by one. Least significant bit is discarded and vacant MSB is filled with value of previous (now shifted one position to right) MSB.
| MSB (Sign) | Right Arithmetic Shift | LSB | |||||
|---|---|---|---|---|---|---|---|
| 1 | 0 | 1 | 1 | 0 | 0 | 1 | 0 |
| → | Shift right 1 position (preserve sign) | ||||||
| 1 | 1 | 0 | 1 | 1 | 0 | 0 | 1 |
MSB (sign bit) is preserved and copied to the next position. Negative numbers remain negative after division.
Cyclic Shift
No bits are lost during a shift. Bits shifted out of one end of register are introduced at other end of register.
Cyclic Shift Example
An 8-bit register containing binary value 10101111 shifted left cyclically three places:
| Original: 1 0 1 0 1 1 1 1 | |||||||
|---|---|---|---|---|---|---|---|
| 1 | 0 | 1 | 0 | 1 | 1 | 1 | 1 |
| Shift left cyclically 3 places | |||||||
| 0 | 1 | 1 | 1 | 1 | 1 | 0 | 1 |
Result: 01111101. Bits 1,0,1 shifted out from left end are introduced at right end.
Logical Shifts in Assembly Language Programming
| Instruction | Explanation |
|---|---|
| LSL n | Bits in ACC are shifted logically n places to the left. Zeros are introduced on the right-hand end |
| LSR n | Bits in ACC are shifted logically n places to the right. Zeros are introduced on the left-hand end |
Important Note
Shifts are always performed on the ACC (Accumulator). The operand n specifies how many places to shift.
Real-Life Example: Fast Multiplication & Division
Binary shifts are used in calculators and processors for fast arithmetic:
Multiplication by 4
Each left shift multiplies by 2. Two left shifts = multiply by 4.
Division by 8
Each right shift divides by 2 (integer division). Three right shifts = divide by 8.
Interactive Binary Shift Simulator
Experiment with different types of binary shifts. Enter a binary number and see how it changes:
Input & Shift Type
Visual Representation
Shift Result
Perform a shift to see the result...
Activity 3: Binary Shift Calculations
Perform the following binary shift operations and show the results:
- Logical left shift of B01101001 by 2 positions
- Logical right shift of B11001100 by 3 positions
- Arithmetic right shift of B10011001 (assuming two's complement) by 1 position
- Cyclic left shift of B10110011 by 4 positions
- What assembly instruction would perform logical right shift by 3 positions on the accumulator?
Solution:
-
B01101001 left shift 2:
Original: 01101001Shift 1: 11010010 (0 introduced at LSB)Shift 2: 10100100 (0 introduced at LSB)Result: 10100100
-
B11001100 right shift 3:
Original: 11001100Shift 1: 01100110 (0 introduced at MSB)Shift 2: 00110011 (0 introduced at MSB)Shift 3: 00011001 (0 introduced at MSB)Result: 00011001
-
B10011001 arithmetic right shift 1:
Original: 10011001 (MSB=1, negative number)MSB (1) preserved and copied: 11001100LSB (1) discardedResult: 11001100 (sign preserved)
-
B10110011 cyclic left shift 4:
Original: 10110011First 4 bits (1011) move to right endResult: 00111011
-
Assembly instruction:
LSR #3
Check Your Understanding: Binary Shifts
1. What is the key difference between logical and arithmetic right shifts? [3 marks]
Answer
- [1 mark] Logical right shift fills the vacant MSB with zero
- [1 mark] Arithmetic right shift fills the vacant MSB with the value of the previous MSB (sign bit)
- [1 mark] Arithmetic shift preserves the sign of the number (for signed/two's complement numbers)
- [Additional] Logical shift is for unsigned numbers, arithmetic shift is for signed numbers
2. What happens to bits in a cyclic shift that doesn't happen in logical or arithmetic shifts? [2 marks]
Answer
- [1 mark] No bits are lost during a cyclic shift
- [1 mark] Bits shifted out of one end of the register are introduced at the other end
- [Additional] This creates a circular rotation of bits rather than discarding them
3. What mathematical operation does a left logical shift by 1 position perform on a binary number? [2 marks]
Answer
- [1 mark] Multiplication by 2
- [1 mark] Each left shift doubles the value (as long as no overflow occurs)
- [Additional] For example, binary 00000101 (5) shifted left becomes 00001010 (10)
4. How many positions would you need to shift left to multiply a number by 16? [2 marks]
Answer
- [1 mark] 4 positions
- [1 mark] Each left shift multiplies by 2, so 2⁴ = 16 requires 4 shifts
- [Additional] In assembly: LSL #4 would multiply by 16
5. What is the assembly instruction for logical shift right and what does it do? [2 marks]
Answer
- [1 mark] LSR n (Logical Shift Right)
- [1 mark] Bits in ACC are shifted logically n places to the right. Zeros are introduced on the left-hand end
- [Additional] The LSB is discarded with each shift
Exam Practice
Practice exam-style questions to test your understanding of bit manipulation concepts.
Exam Style Question from PDF
(i) XOR Operation
Current contents of the ACC are:
Show result after execution of: XOR B00011111
(ii) AND Operation
Current contents of ACC are:
Show the result after the execution of: AND B11110000
Activity 4: Complete Exam Question
A temperature control system uses an 8-bit register to monitor 8 zones. Each bit represents whether a zone's temperature is above threshold (1) or normal (0). The current register value is B01101001.
- Which zones (bit positions) are currently above threshold?
- Write assembly code to set zone 4 (bit 3) to above threshold without affecting other zones
- Write assembly code to check if zone 7 (bit 6) is above threshold
- The register is logically shifted left by 2 positions. What is the new value and what does it represent?
- Explain why a cyclic shift might be used instead of a logical shift in some control systems
Solution:
-
Zones above threshold: Bits at positions where value is 1:
- Bit 0 (zone 1): 1
- Bit 3 (zone 4): 1
- Bit 5 (zone 6): 1
- Bit 6 (zone 7): 1
-
Set zone 4:
LDD TempRegisterOR #B00001000 ; Mask with 1 at bit 3STO TempRegister
-
Check zone 7:
LDD TempRegisterAND #B01000000 ; Mask with 1 at bit 6; If result ≠ 0, zone 7 is above threshold
-
Logical shift left by 2:
Original: 01101001Shift 1: 11010010Shift 2: 10100100New value: 10100100This represents zones 2, 5, 7 above threshold (but note: original zones have shifted left by 2 positions)
-
Cyclic vs Logical shift:
- Cyclic shift preserves all information - no bits are lost
- In control systems, cyclic shifts might be used for rotating through different monitoring modes or for circular buffer implementations
- Logical shift loses information at the ends, which might not be desirable if all bits represent important status flags
Check Your Understanding: Exam Practice
1. What is the result of AND operation between B11001100 and B00110011? [2 marks]
Answer
| Value | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 |
|---|---|---|---|---|---|---|---|---|
| Mask | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 1 |
| AND Result | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Result: 00000000 (All bits become 0 because mask has 0 wherever value has 1, and vice versa)
2. If ACC contains B01010101 and you execute XOR #B11111111, what is the result? [2 marks]
Answer
| ACC | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 |
|---|---|---|---|---|---|---|---|---|
| XOR Mask | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| Result | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 |
Result: 10101010 (All bits are inverted/toggled because XOR with 1 flips the bit)
3. What is the decimal value after logical right shift of B00010100 (20 decimal) by 2 positions? [3 marks]
Answer
- [1 mark] Original: B00010100 = 20 decimal
- [1 mark] After 1 right shift: B00001010 = 10 decimal (20 ÷ 2)
- [1 mark] After 2 right shifts: B00000101 = 5 decimal (20 ÷ 4)
- [Additional] Each logical right shift divides by 2 (integer division)
4. Why might you use AND #B11110000 instead of AND #B00000000 to clear bits? [3 marks]
Answer
- [1 mark] AND #B00000000 clears ALL bits to 0
- [1 mark] AND #B11110000 clears only the lower 4 bits (bits 0-3) to 0
- [1 mark] AND #B11110000 preserves the upper 4 bits (bits 4-7) while clearing the lower 4 bits
- [Additional] This is useful when you want to clear only specific bits while preserving others
5. What is the difference between OR #B00001111 and XOR #B00001111? [3 marks]
Answer
- [1 mark] OR #B00001111 sets bits 0-3 to 1 regardless of their previous state
- [1 mark] XOR #B00001111 toggles bits 0-3 (0→1 or 1→0)
- [1 mark] OR always results in 1s in positions where mask has 1, XOR flips bits where mask has 1
- [Additional] OR is for setting bits, XOR is for toggling or clearing set bits
Key Takeaways
- Bit manipulation involves working with individual bits within binary values using bitwise operations
- Bit masking uses a mask with logical operators to identify, remove or set specific bits
- AND operation is used to check if a bit has been set (1 AND 1 = 1, others = 0)
- OR operation is used to set a bit to 1 (any OR 1 = 1)
- XOR operation is used to clear a bit that has been set (1 XOR 1 = 0, 0 XOR 1 = 1)
- Binary shifts move bits within a register: left shifts multiply by 2, right shifts divide by 2
- Logical shifts fill vacant positions with zeros
- Arithmetic shifts preserve the sign bit for signed numbers
- Cyclic shifts rotate bits with no loss (bits shifted out reappear at the other end)
- LSL #n shifts bits logically n places to the left (zeros introduced at LSB)
- LSR #n shifts bits logically n places to the right (zeros introduced at MSB)
- In monitoring and control systems, each bit in a register can be used as a flag for different sensors or devices
- Bit operations are fast and efficient because they work directly on binary data at the hardware level
- Applications include control systems, networking (subnet masks), graphics programming, and embedded systems
Question Bank
1. Explain the difference between logical, arithmetic, and cyclic binary shifts. [6 marks]
Marking Scheme & Answer
Logical Shift:
- Bits shifted out of register are replaced with zeros
- Used for unsigned numbers
- Left shift multiplies by 2, right shift divides by 2
- Example: LSL #2 shifts left 2 places, zeros at LSB
Arithmetic Shift:
- Sign of number is preserved
- Used for signed numbers (two's complement)
- Right shift fills MSB with previous sign bit
- Preserves negative/positive status
Cyclic Shift:
- No bits are lost during shift
- Bits shifted out are introduced at other end
- Creates rotation of bits
- Useful for circular buffers or rotating status
2. Describe how bit masking is used in monitoring and control systems. [4 marks]
Marking Scheme & Answer
- [1 mark] Each bit in a register can be used as a flag representing status of different sensors or devices
- [1 mark] AND operation checks if a bit has been set (e.g., sensor triggered)
- [1 mark] OR operation sets a bit to 1 (e.g., mark device as needing maintenance)
- [1 mark] XOR operation clears a bit that has been set (e.g., reset alarm status)
- [Additional] Example: 8-bit register for 8-zone temperature system, each bit = zone above threshold
3. Write assembly code to perform the following operations on a byte stored at address 0200: [6 marks]
Marking Scheme & Answer
a) Set bit 5 to 1:
b) Clear bit 2 to 0 (assuming it might be 1):
c) Check if bit 7 is set (without changing value):
4. What are the advantages of using bit manipulation in computer systems? [4 marks]
Marking Scheme & Answer
- [1 mark] Speed up processing - operations are fast and simple at hardware level
- [1 mark] Reduced processing requirements - efficient use of processor resources
- [1 mark] Efficient storage - multiple status flags can be stored in a single byte
- [1 mark] Direct hardware control - essential for device drivers and embedded systems
- [Additional] Fast arithmetic - shifts provide quick multiplication/division by powers of 2
5. Perform these operations and show results in binary: [6 marks]
Marking Scheme & Answer
a) B01101010 AND B11001100
b) B10110011 OR B01100110
c) B11001100 XOR B00110011
6. Explain with examples how binary shifts can be used for fast arithmetic. [4 marks]
Marking Scheme & Answer
- [1 mark] Left logical shift multiplies by 2 for each shift position
- [1 mark] Example: B00000101 (5) LSL #1 = B00001010 (10) = 5 × 2
- [1 mark] Right logical shift divides by 2 (integer division) for each shift position
- [1 mark] Example: B00010100 (20) LSR #2 = B00000101 (5) = 20 ÷ 4
- [Additional] Assembly: LSL #3 multiplies by 8 (2³), LSR #4 divides by 16 (2⁴)
7. A control system uses an 8-bit register where bits 0-2 represent error codes. Write assembly to extract only these bits. [3 marks]
Marking Scheme & Answer
Explanation: AND with 00000111 preserves bits 0-2 (error codes) and clears bits 3-7 to 0, isolating the error code.
8. What is the result of cyclic left shift of B10011001 by 1 position? [2 marks]
Marking Scheme & Answer
- [1 mark] Original: B10011001
- [1 mark] Cyclic left shift 1: MSB (1) moves to LSB position
- [Additional] Result: 00110011
9. How does arithmetic right shift preserve the sign of a negative number? [3 marks]
Marking Scheme & Answer
- [1 mark] MSB (most significant bit) is the sign bit in two's complement
- [1 mark] During arithmetic right shift, the MSB (sign bit) is preserved and copied to the next position
- [1 mark] This ensures negative numbers remain negative after division by 2
- [Additional] Example: B10011001 (-103) arithmetic right shift = B11001100 (-52), sign preserved
10. Why are bitwise operations particularly useful in networking applications? [3 marks]
Marking Scheme & Answer
- [1 mark] Subnet masking uses AND operations to extract network addresses from IP addresses
- [1 mark] Protocol headers use individual bits as flags for different options and settings
- [1 mark] Efficient processing of network packets requires fast bit-level operations
- [Additional] Example: IP address 192.168.1.100 AND subnet mask 255.255.255.0 gives network address 192.168.1.0