Practical Assignment No.
Title:
Write a C program that contains a string (char pointer) with a value \Hello World’. The
program should AND or and XOR each character in this string with 127 and display the result.
Aim:
Write a C program that contains a string (char pointer) with a value \Hello World’. The
program should AND or and XOR each character in this string with 127 and display the result.
Hardaware and Software Requirement:
Intel Based Desktop PC: RAM 4GB
TurboC/Borland C
Program:
#include<conio.h>
#include <stdio.h>
#include<stdlib.h>
void main(){
char str[]="Hello World";
int i,len;
len = strlen(str);
for(i=0;i<len;i++){
printf("%c",str[i]&127);
}
printf("\n");
for(i=0;i<len;i++){
printf("%c",str[i]^127);
}
printf("\n");
for(i=0;i<len;i++){
printf("%c",str[i]|127);
}
printf("\n");
getch();
}
Output:
Conclusion:
It is expected to see "garbage" with OR or XOR. Your string Hello World is pure
ASCII, so it consists of characters with encoding values less than 127. A bitwise AND
with 127 does not change the value, so you will see Hello World.