Wednesday, June 11, 2008

Programming with Bytes :

Programming with Bytes :

The world - 21st Century

There was a huge empire … an empire of cranky devices christened “Computers”. These later on went to be called “Supercomputers” , machines which could do anything and after a few decades probably everything .

Such was the extent to which they had spread themselves over our lives and turning back was unimaginable. But all said and done , everything surviving on earth needs to follow the Rules of the nature i.e even the largest of Dinosaurs were to be created from the tiniest of cells.

Thus the Supercomputers that we see today work on nothing more than a bit a.k.a. cells of the computer . A ‘bit’ symbolizes the smallest unit of information that can be stored in a memory (Artificial).So what does it store afterall . Any resemblence or attempt to relate this to the human brain could prove fatal as the complexity of the human is really complex. Hats off to the Human brain anyways especially the one that makes me write this.

Well back to what we were discussing , a bit . A bit stores either a ‘ON’ or a ‘OFF’ , this can be very easily an safely be related to a switch , a very normal Electric switch , the one one at home used to turn ON or OFF a bulb.

So how do the 108 keys on your keyboard become recognisable data to the computer.

Lets take an example , say A , * , 1 need to be represented in an understandable format to the processor.

Now for the computer these 3 are no different from each other , neither does it understand that these are English Alphabets , a special symbol , a Maths number respectively.For the processor these are mere unique values which need to be always stored in a particular form onto the memory such that on reading from the processor , for those to whom it really matters (i.e you and me) do get to understand as them as English Alphabets , a special symbol , a Maths number respectively.

Here is where we come an imporatant industry standard , ASCII - Short for American Standard Code for Information Interexchange . which assigns letters, numbers and other characters within the 256 slots available in the 8-bit code.

So ASCII values come as great help over here. ASCII values are standard values that are uniform all around the world . So A is said to have an ASCII value ( let me tell you its 65 ) We have a Appendix ‘A’ section later on in this blog for a list of ASCII values.

At this stage let me introduce you to Procy , Procy is our friendly processor who would amuse and awe you with his antics and in the process help us understand the working of a processor.

Over to Procy …

Hello Everyone ! A very good day to you !


Well to start with let me be courteous enough to introduce myself. I am Procy , I am a processor. The Adam of my family came to earth sometime around in the early 1970. The first of my kind as far as I have heard was a quite fat and bulky , almost the size of a cricket bat . But since then , with all these slimming packages available , here I am the slim beauty , a mirror cracking material ! Oops am boasting too much , well I am just telling the truth.

Now , let me take 2 cases for our study !

1) A simple file (to keep the complexity to the bare minimum let us take a “text” file written and saved in a notepad) . We will migrate to MS Word documents later on this section.

If we type the letter ‘A’ in a notepad and save it onto the harddisk with under a text file format , we notice that it takes 1 byte of space in the memory.You may also take a notepad on your system and type the letter ‘A’ in it (without quotes) .

Now how does this ‘A’ get stored in the memory finally . I mean if you just pluck out the memory and are somehow able to view or read the contents marked at the location where the file is saved.

Well as per my understanding the ‘A’ would first get converted into its ASCII value ( Just to remind – its 65 )and then this again gets converted into an 8 bit digit in its binary form . So this is how it would be stored in the bare memory , and the Notepad program that was developed would have in its list of important values – the address where this particular 8 bit value resides.

So from an OS perspective when we again try to open the file using NotePad :

First the program files are loaded into memory , ( now the RAM ) , then the data whose address in the harddisk would be stored along with the tasks of the NotePad application will be copied on to the RAM.

Now these ASCII values are converted to human readable characters by the NotePad application (well that’s what it does and sells for).

If we are clear with the saving and retrival of data for a NotePad application , we can move on to an MS Word document application which also stores along with the basic structure of the alphabet , the extra formatting parmeters like the font , size , indentation etc.