Exercise-2
2. 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.
#include <stdio.h>
int main(void)
{
const char *str = "Hello World";
int i;
printf("Original String : %s\n\n", str);
printf("AND with 127 : ");
for (i = 0; str[i] != '\0'; i++) {
printf("%c", (unsigned char)(str[i] & 127));
}
printf("\nOR with 127 : ");
for (i = 0; str[i] != '\0'; i++) {
printf("%c", (unsigned char)(str[i] | 127));
}
printf("\nXOR with 127 : ");
for (i = 0; str[i] != '\0'; i++) {
printf("%c", (unsigned char)(str[i] ^ 127));
}
printf("\n");
return 0;
}
Simple Output:
Original String : Hello World
AND with 127 : Hello World
OR with 127 :
R with 127 : 7_(