LAB 4 RANA HARIS HAFEEZ 2020 EE 272 (Respected sir I submitted this lab late due to my online classes issue and desktop not availability issue ) CODE NO 1 #include<stdio.h> //#include"mylib.h" // Global variables section int a=8; // Any number that is less than or equal to 4 bit int remainder = 0, quotient = 0; int b3, b2, b1, b0; // Function prototype section int main(void); // Function definition int main(void) { // Print binary value remainder = a%2; quotient = a/2; b0 = remainder; remainder = quotient %2; quotient = quotient /2; b1 = remainder; remainder = quotient %2; quotient = quotient /2; b2 = remainder; remainder = quotient %2; quotient = quotient /2; b3 = remainder; printf("Binary value of %d is %d%d%d%d \n", a, b3, b2, b1, b0); return 0; } CODE NO 2 // Pre-processor Section #include<stdio.h> // <> means use standard library path to locate stdio.h //#include"mylib.h" // Global variables section int a=128; // Any number that is equal to 8 bit int remainder = 0, quotient = 0; int b7, b6, b5, b4, b3, b2, b1, b0; // Function prototype section int main(void); // Function definition int main(void) { // Print binary value remainder = a%2; quotient = a/2; b0 = remainder; remainder = quotient %2; quotient = quotient /2; b1 = remainder; remainder = quotient %2; quotient = quotient /2; b2 = remainder; remainder = quotient %2; quotient = quotient /2; b3 = remainder; remainder = quotient %2; quotient = quotient /2; b4 = remainder; remainder = quotient %2; quotient = quotient /2; b5 = remainder; remainder = quotient %2; quotient = quotient /2; b6 = remainder; remainder = quotient %2; quotient = quotient /2; b7 = remainder; printf("Binary value of %d is %d%d%d%d%d%d%d%d \n", a, b7, b6, b5, b4, b3, b2, b1, b0); return 0; } Code no 3 // Pre-processor Section #include<stdio.h> // <> means use standard library path to locate stdio.h //#include"mylib.h" // Global variables section int a=20291; // Any number that is equal to 16 bit int remainder = 0, quotient = 0; // Function prototype section int main(void); // Function definition int main(void) { int b3, b2, b1, b0; // Print hexa value remainder = a%16; quotient = a/16; b0 = remainder; remainder = quotient %16; quotient = quotient /16; b1 = remainder; remainder = quotient %16; quotient = quotient /16; b2 = remainder; remainder = quotient %8; quotient = quotient /8; b3 = remainder; printf("Hexadecimal value of %d is %d%X%d%d \n", a, b3, b2, b1, b0); int c4, c3, c2, c1, c0; // Print octa value remainder = a%8; quotient = a/8; c0 = remainder; remainder = quotient %8; quotient = quotient /8; c1 = remainder; remainder = quotient %8; quotient = quotient /8; c2 = remainder; remainder = quotient %8; quotient = quotient /8; c3 = remainder; remainder = quotient %8; quotient = quotient /8; c4 = remainder; printf("Octadecimal value of %d is %d%d%d%d%d\n", a, c4 ,c3, c2, c1, c0); return 0; } CODE NO 4 // Function definition int main(void) { int a = 291; int b = 192; int c = 0; printf("Bitwise AND operator c = %d\n", c); c = a|b; printf("Bitwise OR operator c = %d\n", c); c = a^b; printf("Bitwise AND operator c = %d\n", c); c = ~a; printf("Bitwise NOT operator c = %d\n", a = c); return 0; } CODE NO 5 // Function definition int main(void) { int unsigned a=291; int signed b=192; int W = 0; int X = 0; int Y = 0; int Z = 0; W = a>>2; printf("The value of W is %d\n", W); X = b>>2; printf("The value of X is %d\n", X); Y = a<<2; printf("The value of Y is %d\n", Y); Z = b<<2; printf("The value of Z is %d\n", Z); return 0; } CODE NO 6 // Function definition int main(void) { int signed a=291; int signed b=192; int W = 0; int Y = 0; int Z = 0; int X = 0; int K = 0; int I = 0; int J = 0; W= a++; printf("the value of W is %d\n", W); Y = ++a; printf("the value of Y is %d\n", Y); Z = b--; printf("the value of Z is %d\n", Z); X = --b; printf("the value of X is %d\n", X); K = (a++)-(++b); printf("the value of K is %d\n", K); I = W-Y; printf("the value of I is %d\n", I); printf("//The value of I is obtained by substracting Y from W as Y gives the same value as its post increment and W gives input a with +2 \n"); J = Z-X; printf("//The value of J is %d\n", J); printf("//The value of J is obtained by substracting X from Z as X gives the same calue as it is post decrement and Z gives a input with -2 \n"); return 0; } CODE NO 7 // Function definition int main(void) { int a=291; int b=192; int p1 = 0; int p2 = 0; int y = 0; int z = 0; int P1= 0; int P2 = 0; p1 = &a; printf("The value of p1 = %p\n", p1); printf("//The pointer variable p1 stores the values of the variable a and then the & function copies the address of the variable a located in the memory and places it in p1 \n"); p2 = &b; printf("The value of p2 = %p\n", p2); printf("//The pointer variable p2 stores the values of the variable b and then the & function copies the address of the variable b located in the memory and places in p2 \n"); y = a; printf("The value of y = %d\n", y); printf("//Now the value we assigned to variable a is assigned to variable y \n"); z = b; printf("The value of z = %d\n", z); printf("//Now the value we assigned to variable b is assigned to variable z\n"); P1 = 3; // let *p1 = P1 printf("The value of *p1 = %d\n", P1); printf("//Here we assigned value to a pointer\n"); P2 = 7; // let *p2 = P2 printf("The value of *p2 = %d\n", P2); printf("//Here we assigned value to a pointer\n"); printf("The value of all = %u%u%u%u%u%u \n", p1, p2, y, z, P1, P2 ); printf("//%u is used for unsigned integer. Since the memory address given by the signed integer address operator %d, to get this value in unsigned integer, Compiler returns the unsigned integer value for this address \n"); return 0; }