Number System – Part II


From the previous session we have seen how to convert binary to decimal and decimal to binary number. This section I will focus on the importance of number system and how they are used in operating systems.

 

When we first learn programming language we often tend to learn the constructs / functions provided by the language. One should think what happens when you assign

Create a variable with data type eg: int x . How does compiler converts the int to represent 4 bytes of memory space, what is a byte , what is a bit , where are these allocated etc..

 =================================================================================

 

 

Bit: bit can hold smallest data in computer systems. Bit can represent only 2 states, and these states can be anything, a bit can represent 2 countries, 2 football players , 2 actors etc.. You have to understand that bit by itself doesn’t represent anything , then how to say that Bit holds values ?, this is done using programming language with the help of Data structures.

 

Below examples show you the different values a bit can handle

 

                                                 Country 2

 

Eg :                        Bit                                                      

                                                

                                                 Country 2

 

 

 

 

                                                 Horse

 

                               Bit  

 

                                                 123488

 

 

 

 

 

Please remember that at the end of the day you would be only dealing with bits, because datatypes group number of bits and the actual data resides in the bits.

 

 =================================================================================

 

 

 Bytes: Operating systems uses byte addressable for memory and I/O operations. Byte is group of bits , 8 bit grouped together to form a byte, with each bit capable of representing 2 states, 8 bits can represent 256 different states / values. These values conversion to ASCII , UTF etc. To elaborate more programmers use ASCII character set where character ‘A’ is represent as 41h and not ‘A’, because processor doesn’t understand anything apart from binary ( 0’s and 1’s ) , so the binary equivalent of ‘A’ would be processed.

 

We will write small assembly programs to understand more about the bits and bytes.

So now we understand if someone says “ The bit value might be corrupted”

 

 

==================================================================================

 

 

 

Words: This forms another grouping and a word can be 16 bit or 32 bit depending on the architecture. If its 32 bit then 4 bytes constitutes a word so the maximum value we can represent is 2 32 = 4294967295.

 

I would like to emphasize the concept and not the calculation behind it . The concept is Grouping of bits , the grouping might be int datatype, float datatype, char datatype or any other datatype, but at the end its all grouping of bits. Binary conversion of 232  is

 

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

1

                                 16 bytes                                          16 bytes

High Order  byte                                                                                       low order byte

 

 

216  * 2 16 = 4294967295 / 4 bytes When you learn HLL ( like c , c++ ) , you would be exposed to data types which would allocate defined amount of memory , you should think about these data types as grouping of bits as I mentioned above.

 

If you have installed Microsoft Visual Studio ,you can quickly compile a c program playing around with bits

 

 

================================================================================

Exercise:

 

a)      What happens when you initialize int a = 4294967295 ( int datatype being 32 bit )

And try to print the value ?

 

 

b)      What is the flow of execution till the processor executing the bit starting from

Compiler ?

 

 

  

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s