Title: Boolean Functions

Total Page:16

File Type:pdf, Size:1020Kb

Title: Boolean Functions

ECT109 Week 4 iLab 2 Page 1 of 2

Name: ______Grade: ______

Title: Boolean Functions

I. OBJECTIVES

This iLab uses the Python Boolean functions to perform Boolean operations on numerical values. The challenge in this lab is to use the OR and XOR Boolean functions in addition to the given AND Boolean function..

II. DESCRIPTION

George Boole pioneered a mathematical concept known as Boolean expressions, or Boolean algebra. Four of the basic Boolean operation are the AND, the OR, the XOR, and the NOT operations. Programs use these operations to evaluate the relationship between variables and make decisions based on those relationships. Comparing two or more variables, bitwise, results in either a True (1) or False (0) outcome.

Bitwise operations Python operator Example AND & n & m OR | a | b XOR ^ e ^ f

Table 1 - Python Operators

to display a number function Example in binary bin(x) bin(5) = 0b101 In hexadecimal 0x%x ‘0x%x’ %46 = 0x2e

Table 2 - Number Conversions

III. PROCEDURE

1. Boot up the Raspberry Pi (RPi).

2. Open IDLE.

3. Enter the program below.

Name = ‘Put Your Name Here’

Class= ‘ECT109’

Assignment = ‘Week 4 Lab 2’ ECT109 Week 4 iLab 2 Page 2 of 2

#------

# Boolean bitwise AND operator

#------

print Name

print Class

print Assignment

print

print 'AND operator' n = input(‘Enter 1st Number: ‘) m = input(‘Enter 2nd Number: ‘) print n, bin(n), '0x%x' % n print m, bin(m), '0x%x' % m x = n & m print n, 'AND', m, ' = ', x, bin(x), '0x%x' % x print

4. This Python program will perform the AND bitwise operator. Your assignment is to add to the above program the OR and XOR bitwise operators.

5. Verify your results.

6. Upload the completed Python program (FiLastNameLab4-2.py) to the weekly iLab Dropbox.

Recommended publications