BBB Binary Bits Bytes Language of computers Computer

BBB - Binary, Bits, Bytes Language of computers Computer only understand 0 s and 1 s Base 2, 2 variations of 1 bit, 0 and 1 (0 to base – 1) 000000010 00000011 00000100 00000101 00000110 00000111 00001000 00001001 00001100 00001011 00001100 1 byte has 8 bits 1 word has 16 bits 1 double word has 32 bits example: 00000001 in binary = 1 in decimal 00000011 in binary = 3 in decimal 1

Numbering systems Number systems and converting data from one numbering system to another http: //www. geocities. com/msaleemyusuf/numberingsystem. ppt OR http: //mysite. verizon. net/msaleemyusuf/numberingsystem. ppt There are more slides after this page 2

If, if/else structure if structure • Test if condition is true or false. If condition is true execute, otherwise ignore if (conditional statement is true) execute one statement { means START of a block of statements if (conditional statement is true) } means END of a block of statements { execute all statements with this block …… …… …… } 3

If, if/else structure if structure • Test if condition is true or false. If condition is true execute, otherwise ignore if (conditional statement) { execute all statements with this block { means START of a block of statements } else if (conditional statement) } means END of a block of { statements execute all statements with this block } else { execute all statements with this block } 4

Decision Making Table of relational operators on next slide if Grade >= 80 else if cout << “You did greatn”; false Grade >= 70 else true cout << “You did OKn”; false cout << “You did NOT Passn”; 5

Equality & Relational Operators • Equality and relational operators –Lower precedence than arithmetic operators 6

C++ Relational Operators • Relationship between two expressions • Return value is bool, true/false > Greater than, >= Greater or Equal to, < Lower than, <= Lower than or Equal to == Equal to, != Not equal to int a = 2; int b = 5; int c = 10; bool result; result = a > b; result will have 0, result = b > a; result will have 1, result = a == b; result will have 0; result = b > a + c; result will have 0, FALSE TRUE FALSE 7

C++ Operators Logical Operators • The way in which TRUE and FALSE values can be connected together, returns bool, true/false && (AND), || (OR), ! (NOT) if ( (a >= b) && (a != c) ) cout << “We found it” << endl; else cout << “Did not find itn”; if (!(a > b)) cout << “a is not greater than bn”); 8

C++ Bitwise operators - Truth Tables & AND (& is bitwise AND, && is logical) | OR ~ NOT (~ is bitwise OR, ! is logical) ^ XOR (bitwise exclusive OR) (| is bitwise OR, || is logical) >> Shift right << Shift Left 0 = FALSE, 1 (OR ANY VALUE EXCEPT 0) TRUE Cond 1 Cond 2 Cond 1 & Cond 2 Cond 1 | Cond 2 Cond 1 ^ Cond 2 0 0 0 1 0 1 1 1 0 9

Truth Tables 10

#include <iostream> using namespace std; int main() { int num 1, num 2; cout << "Enter two ints: "; cin >> num 1, num 2; if ( num 1 == num 2 ) cout << num 1 << " is equal to " << num 2 << endl; if ( num 1 != num 2 ) cout << num 1 << " is not equal to " << num 2 << endl; if ( num 1 > num 2 ) cout << num 1 << " is greater than to " << num 2 << endl; if ( num 1 < num 2 ) cout << num 1 << " is less than to " << num 2 << endl; if ( num 1 >= num 2 ) cout << num 1 << " is greater than or equal to " << num 2 << endl; if ( num 1 <= num 2 ) cout << num 1 << " is less than or equal to " << num 2 << endl; return 0; } 11

End of lecture 2 Click on the following link to return to the website http: //www. geocities. com/MSaleem. Yusuf/lecture_2. htm http: //mysite. verizon. net/MSaleem. Yusuf/lecture_2. htm 12
- Slides: 12