0 likes | 40 Views
Binary shifts, also known as logical shifts, involve moving binary values left or right. This concept is essential in computational thinking and programming theory, especially when dealing with data representation. By shifting bits within a byte, calculations such as multiplication and division by powers of 2 can be efficiently performed. This summary covers left and right shift examples, practice questions, and the importance of mastering binary shift calculations in computer science.
E N D
Computational thinking, algorithms and programming Theory: 2.6 – Data Representation Binary Shift Binary Shift Computer Science (J276/02)
Computational thinking, algorithms and programming Binary Shift 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. Multiply or divide by Shifts 2 = 21 1 Computer Science 4 = 22 2 As we know, 8 bits are called a byte, which is the smallest addressable unit of memory. 8 = 23 3 16 = 24 4 32 = 25 5 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. 64 = 26 6 128 = 27 7
Computational thinking, algorithms and programming Left Shift Example Left Shift Example Example: 3 x 8 128 0 64 0 32 0 16 0 8 0 4 0 2 1 1 1 Computer Science To multiply by 8, we need to shift the binary digits to the left by 3 places. 2 x 2 x 2 = 8 128 0 0 64 0 0 32 0 0 16 0 1 8 0 1 4 0 0 2 1 0 1 1 0 16 +8 =24
Computational thinking, algorithms and programming Practise Questions Practise Questions Write these out in binary: 1. 1111 x 4 = Multiply or divide by Shifts 2 = 21 1 Computer Science 4 = 22 2 8 = 23 3 2. 100001 x 2 = 16 = 24 4 32 = 25 5 Convert to binary first: 64 = 26 6 128 = 27 7 3. 70 x 8 =
Computational thinking, algorithms and programming Practise Questions Practise Questions Convert to binary first: Computer Science 3. 70 x 8 = 01000110 x 8 = 00110000
Computational thinking, algorithms and programming Right Shift Example Right Shift Example Example: 192 ÷ 16 128 1 64 1 32 0 16 0 8 0 4 0 2 0 1 0 Computer Science To divide by 16, we need to shift the binary digits to the right by 4 places. 2 x 2 x 2 x 2 = 16 128 1 0 64 1 0 32 0 0 16 0 0 8 0 1 4 0 1 2 0 0 1 0 0 8 +4 =12
Computational thinking, algorithms and programming Practise Questions Practise Questions Multiply or divide by Shifts 2 = 21 1 Write these out in binary: 4 = 22 2 8 = 23 3 1. 11001000 ÷ 8 = Computer Science 16 = 24 4 32 = 25 5 2. 00010110 ÷ 2 = 64 = 26 6 128 = 27 7 Convert to binary first: 3. 224 ÷ 32 =
Computational thinking, algorithms and programming Practise Questions Practise Questions Write these out in binary: 1. 11001000 ÷ 8 = 00011001 Computer Science 2. 00010110 ÷ 2 = 00001011 Convert to binary first: 3. 224 ÷ 32 = 11100000 ÷ 32 = 00000111
Computational thinking, algorithms and programming Theory Plenary Plenary- - Self Assessment Self Assessment Using WWW and EBI rate yourself against todays objectives: 1. To be able to demonstrate an understanding of binary shift calculations. Computer Science Next theory lesson: Hexadecimal Conversions