Header Ads

23 - WAP to Print Lower Case to Upper Case using Bitwise Operators in C

This Program prints the given string from Lower Case to Upper Case using Bitwise Operators in C.

#include <stdio.h>
#include <string.h>

//Global declaration of variables
const int x = 32;
int idx;

//Calling of Uppercase conversion function
char *uppercase(char *str)
{
 //Bitwise ANDing (&) and then negation (~) of 32 letters to obtain Upper case.
 for (idx=0; str[idx]!= '\0'; idx++)
  str[idx] = str[idx] & ~x;
 return str;
}

// Main Function Program
int main()
{
 char str[100];
 printf("Enter a String in Lower Case: ");
 scanf("%s", str);
 //Printing the String in Upper Case  
 printf("String in Upper Case : %s\n", uppercase(str));
 return 0; 
}   

Program Output:

No comments