Well, I am under the study of the Assembly language and I seriously hope that I would be able to complete it this time. I have a very bad habit of leaving everything unfinished, most of my best friends hate me for this. I am seriously considering leaving this habit. Well, as the book contains some programming problems that I need to do to make sure that I am learning to code too. I will be posting about the problems that I find bit different. It is the first installment of this series. Problem is simple, you need to enter a character and without using any of the topper and to lower function you need to change the case of the character entered. Seems simple huh ? No. It is not because another part says no tinkering with the ASCII value, you need to apply some of the ignorant concepts that you have read and ignored like hell. You need to temper with the bits of the character. So, here is the thing.

Computer understands the value of 0 and 1 only. it stores the values in the form of 0 and 1 only.  I assume that you know the fact the C compiler stores the char in 8 bits. It implements ASCII character set. The ASCII character set is divided into 4 group of 32 characters,  making it a group of 128 characters. 0 to 31 is a collection of non printable characters called control characters. The second group of 32 ASCII character codes holds punctuation symbols, special characters, and the numeric digits. The next group of 32 characters is of Higher Order English alphabets, 26 and rest 6 for special characters. Again last six is for lower order English alphabets and 6 for some special characters.

Consider the fallowing figure.

As you can see, there is difference in the bit 5 only. Interesting, huh ? So, our task has been simplified a lot, we need simply need to do some king of operations to set the value of the 5th bit as required and leave the rest ones as they are now. So, here is the program. It is the program for changing Lower Case to upper one.

# include "stdio.h"
# include "conio.h"
int main()
{
     char a[]="Can not say good bye to Yesterday";
     int i;
     for(i=0;a[i]!=NULL;i++)
     {
             a[i]=a[i]&0xDF;
             printf("%c",a[i]);
     }
     return 0;
}

And this one is for changing Higher Order to Lower One.

# include "stdio.h"
# include "conio.h"
int main()
{
     char b[]="the best is yet to come";
     for(i=0;b[i]!=NULL;i++)
     {
          b[i]=b[i]|0x20;
          printf("%c",b[i]);
     }
     return 0;
}

I seriously do not want to explain the concept, behind these logical operations because I already did the main thing. It is up to you to figure out about how these operations actually work.

And as for as the the Strings are concerned, they are songs of a very good game, Metal Gear Solid. You can listen to them. They are awesome and you may feel the same if you are unfortunate like me to go through the conditions I went through. Even then, Good Luck.

Advertisements