Header Ads

24 - WAP to Print Upper Case to Upper Case using Bitwise Operators in C

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

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

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

//Calling of Lowercase conversion function
char *lowercase(char *str)
{
    //Bitwise ORing (&) with that of 32 letters to obtain lower 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 Upper Case: ");
     scanf("%s", str);
     //Printing the String in Upper Case  
     printf("String in Lower Case : %s\n", lowercase(str));
   return 0; 
}  

Program Output:

No comments