Tutorial 01 PDF

Title Tutorial 01
Author Obancium
Course Discrete Structures
Institution Queensland University of Technology
Pages 2
File Size 53.6 KB
File Type PDF
Total Downloads 67
Total Views 181

Summary

from QUT...


Description

CAB203 Tutorial 1

Modular arithmetic Calculate:

1. 17 mod 5 2. 36 mod 7 3. 5 + 7 mod 3 4. 5 · 4 mod 3 5. Stretch question Show that if r is the remainder when a is divided by b (i.e. a = bq + r) then a ≡ r (mod b). 6. Stretch question Apply the definition of modular equivalence to show that if a ≡ b (mod n) and b ≡ c (mod n) then a ≡ c (mod n).

Exponents Use the laws of exponents and logarithms to calculate the following (don’t use a calculator): 1. 215 · 23 bits expressed in kilobits 2. Express 85 with base 2 3. log2 256 16 4. log2 83 5. Stretch question Use the fact that nx · ny = nx+y to show that logn ab = log n a + logn b using only the basic properties of logarithms (i.e. logn nx = x and x = nlog n x ).

Bits 1. Count: (a) How many different 8-bit strings are there? (b) How many gigabits are there if you have one bit for every possible 32-bit string? (c) How many bits are required if you need 18 unique bit strings? 2. Calculate the following expressions using bitwise operations:

(a) 0011 & 1010 (b) 0011 | 1010 (c) 0011 ˆ 1010 (d) ∼1010 3. In the following, explain how to use bitwise operators to manipulate individual bits. (a) In x = 1010, turn on bit 2 (b) In x = 1100, turn off all but bits 1 and 2 (c) In x = 1110, flip bit 3 (d) In x = 0110, turn off bit 1

Python bit manipulation 1. Define a Python function that takes two integers, x and j, and returns a value which is x, but with bit j set (set to 1). 2. Define a Python function that takes two integers, x and j, and returns a value which is x, but with bit j cleared (set to 0). 3. Define a Python function that takes two integers, x and j, and returns a value which is x, but with bit j flipped. 4. Define a Python function that takes two integers, x and j, and returns True if the jth bit of x is 1, otherwise False.

Page 2...


Similar Free PDFs