J 27602 Computational thinking algorithms and programming Computer

  • Slides: 9
Download presentation
(J 276/02) Computational thinking, algorithms and programming Computer Science Theory: 2. 6 – Data

(J 276/02) Computational thinking, algorithms and programming Computer Science Theory: 2. 6 – Data Representation Binary Shift

Computational thinking, algorithms and programming Computer Science Binary Shift A binary shift (also known

Computational thinking, algorithms and programming Computer Science Binary Shift A binary shift (also known as a logical shift) is just as the name suggests; the shifting or moving of binary values to the left or the right. As we know, 8 bits are called a byte, which is the smallest addressable unit of memory. So, a binary shift is moving each bit in a defined direction (left or right). Since we work in bytes, any bits that fall out of that 8 bit block are lost forever. Multiply or divide by Shifts 2 = 21 1 4 = 22 2 8 = 23 3 16 = 24 4 32 = 25 5 64 = 26 6 128 = 27 7

Computational thinking, algorithms and programming Computer Science Left Shift Example: 3 x 8 128

Computational thinking, algorithms and programming Computer Science Left Shift Example: 3 x 8 128 0 64 0 32 0 16 0 8 0 To multiply by 8, we need to shift the binary digits to the left by 3 places. 128 0 0 64 0 0 32 0 0 16 0 1 16 4 0 2 1 1 1 2 x 2 x 2=8 8 0 1 +8 4 0 0 2 1 0 1 1 0 =24

Computational thinking, algorithms and programming Computer Science Practise Questions Write these out in binary:

Computational thinking, algorithms and programming Computer Science Practise Questions Write these out in binary: 1. 1111 x 4 = 2. 100001 x 2 = Convert to binary first: 3. 70 x 8 = Multiply or divide by Shifts 2 = 21 1 4 = 22 2 8 = 23 3 16 = 24 4 32 = 25 5 64 = 26 6 128 = 27 7

Computational thinking, algorithms and programming Computer Science Practise Questions Convert to binary first: 3.

Computational thinking, algorithms and programming Computer Science Practise Questions Convert to binary first: 3. 70 x 8 = 01000110 x 8 = 00110000

Computational thinking, algorithms and programming Computer Science Right Shift Example: 192 ÷ 16 128

Computational thinking, algorithms and programming Computer Science Right Shift Example: 192 ÷ 16 128 1 64 1 32 0 16 0 8 0 To divide by 16, we need to shift the binary digits to the right by 4 places. 128 1 0 64 1 0 32 0 0 16 0 0 4 0 2 0 1 0 2 x 2 x 2 = 16 8 0 1 4 0 1 8 +4 2 0 0 1 0 0 =12

Computational thinking, algorithms and programming Computer Science Practise Questions Multiply or divide by Shifts

Computational thinking, algorithms and programming Computer Science Practise Questions Multiply or divide by Shifts Write these out in binary: 2 = 21 1 4 = 22 2 1. 11001000 ÷ 8 8 = 23 3 16 = 24 4 32 = 25 5 64 = 26 6 128 = 27 7 2. 00010110 ÷ 2 = = Convert to binary first: 3. 224 ÷ 32 =

Computational thinking, algorithms and programming Computer Science Practise Questions Write these out in binary:

Computational thinking, algorithms and programming Computer Science Practise Questions Write these out in binary: 1. 11001000 ÷ 8 = 00011001 2. 00010110 ÷ 2 = 00001011 Convert to binary first: 3. 224 ÷ 32 = 11100000 ÷ 32 = 00000111

Computational thinking, algorithms and programming Computer Science Theory Plenary- Self Assessment Using WWW and

Computational thinking, algorithms and programming Computer Science Theory Plenary- Self Assessment Using WWW and EBI rate yourself against todays objectives: 1. To be able to demonstrate an understanding of binary shift calculations. Next theory lesson: Hexadecimal Conversions