Back to 课程

Computer-Science-A-level-Ocr

0% Complete
0/0 Steps
  1. 3-3-networks
    8 主题
  2. 3-2-databases
    7 主题
  3. 3-1-compression-encryption-and-hashing
    4 主题
  4. 2-5-object-oriented-languages
    7 主题
  5. 2-4-types-of-programming-language
    4 主题
  6. 2-3-software-development
    5 主题
  7. 2-2-applications-generation
    6 主题
  8. 2-1-systems-software
    8 主题
  9. 1-3-input-output-and-storage
    2 主题
  10. 1-2-types-of-processor
    3 主题
  11. 1-1-structure-and-function-of-the-processor
    1 主题
  12. structuring-your-responses
    3 主题
  13. the-exam-papers
    2 主题
  14. 8-2-algorithms-for-the-main-data-structures
    4 主题
  15. 8-1-algorithms
    10 主题
  16. 7-2-computational-methods
    11 主题
  17. 7-1-programming-techniques
    14 主题
  18. 6-5-thinking-concurrently
    2 主题
  19. 6-4-thinking-logically
    2 主题
  20. 6-3-thinking-procedurally
    3 主题
  21. 6-2-thinking-ahead
    1 主题
  22. 6-1-thinking-abstractly
    3 主题
  23. 5-2-moral-and-ethical-issues
    9 主题
  24. 5-1-computing-related-legislation
    4 主题
  25. 4-3-boolean-algebra
    5 主题
  26. 4-2-data-structures
    10 主题
  27. 4-1-data-types
    9 主题
  28. 3-4-web-technologies
    16 主题
课 Progress
0% Complete

What are Logical Shifts?

  • Logical shifts are the process of moving the bits in a binary number to the left or right by a specified number of places

  • Bitwise manipulation uses logical operators like AND, OR, XOR, and NOT to manipulate binary numbers

Logical Shifts

  • Logical binary shifts are operations performed on binary numbers where all the bits in the number are moved left or right by a specified number of positions

  • These shifts are commonly used in computer programming and digital systems

  • There are two types of logical binary shifts: Left and Right

Example left shift

The following number is shifted by two places to the left. 

Example Left shift

Original number: 00001110 = 14

Left shift (2) result: 00111000 = 56

Each left shift has doubled the number:

  • Original value = 14

  • Left shift 1 – Doubled the number to 28

  • Left shift 2 – Doubled the number to 56

Example right shift

The following number is shifted by three places to the right. 

Example Right Shift

Original number: 11001000 = 200

Right shift (3) result: 00011001 = 25

Each right shift has halved the number:

  • Original value = 200

  • Right shift 1 – Halved the number to 100

  • Right shift 2 – Halved the number to 50

  • Right shift 3 – Halved the number to 25

Bitwise Manipulation

What is a mask?

  • A mask is a binary number used in bitwise operations to isolate, modify, or test specific bits in another binary value

  • Think of a mask as a filter: it lets certain bits through and blocks others, depending on the bitwise operation being used

Why use a mask?

  • To extract certain bits from a binary number (e.g. the lower 4 bits)

  • To set specific bits to 1

  • To clear specific bits (set them to 0)

  • To toggle (flip) specific bits

Bitwise AND operation

If both bits are 1 in the binary number and the mask, the result will be 1. Otherwise, the result will be 0.

Description

128

64

32

16

8

4

2

1

Binary 

1

0

1

1

1

0

0

1

Mask

0

0

1

1

0

0

0

0

Result

0

0

1

1

0

0

0

0

Bitwise OR operation

If either bit is 1 in the binary number or the mask, the result will be 1. Otherwise, the result will be 0.

Description

128

64

32

16

8

4

2

1

Binary 

1

1

0

0

1

0

1

0

Mask

0

1

1

1

0

0

0

0

Result

1

1

1

1

1

0

1

0

Bitwise XOR operation

If only 1 of the bits is 1 in the binary number or the mask, the result will be 1. Otherwise, the result will be 0.

Description

128

64

32

16

8

4

2

1

Binary 

1

0

1

0

1

0

1

0

Mask

0

0

1

1

0

0

0

0

Result

1

0

0

1

1

0

1

0

Responses

您的邮箱地址不会被公开。 必填项已用 * 标注