Sunday 4 May 2014

Everything you need to know about...

In this post we will cover answers to questions like why 1KB = 1024 bytes why not 1000 bytes,why there are only 256 character or ASCII(s),how to determine the range of certain data types and...
This post hence,will be helpful for noob programmers and computer science students...


  • I know,you know computer only knows 0's and 1's.But do you know why ?
    Answer to that lies on the hardware which we use.Main component of the hardware of now days computers are semiconductors which works on currents and voltages.
    So if there is any current on the circuit computer reads it as 1 and the region of no current is read as 0.


  • All of you know(i think..) that 8bits=1bytes but did you ever thought why is it so??
    Well to be fare it isn't always because there are cases when computers or programs use other no. of bits for a byte.but 8 is the size which is most commonly used,as it proves to be the most easy yet accurate choice for calculation and operation purposes...
    You can check how much bits your computer/operating system calls as byte (I'm sure it will be 8),by a macro named CHAR_BIT included in the header file "limits.h".
    TIP : If you don't know what macro and header file are,then you need to go through a book of C-programming.If you want help in that,then comment
    NOTE : As 8 is the most widely used packet of bits for a byte,so we too will continue with that in rest of the post.

  • Now the question is why 1 kilobyte=1024 byte why not 1000 bytes ??
    As you know we use decimal number system,i.e. we have 10 digits to work and calculate everything and that's why when we move from one unit to another unit of any quantity we do so in power of 10.For example : 1 Kilogram=103Gram.
    and this is what we do to traverse from one unit of storage to another.But you know computer only understands the language of 0's and 1's and hence it has only two digits to work on.
    hence this is done in terms of power of 2 (2n).So at the time to decide what will be the multiplication factor to transverse from unit to another they do the calculation as under
    So to calculate that they(early engineers) started putting all the numbers in power of two..until they got the nearest number to 1000(because the unit from S.I. to kilo,and so on increase in the multiple of 1000), Now let's see what they've got...
                   21 = 2   which was no way near to 1000
                   22 = 4   and so this was...hence they moved on and on until they reached 10
    Because, 210 = 1024   which was best equivalent of 1000 (best in the binary system).
    and this was the sweet little story of how 1024 bytes became equal to 1 kilobytes.

  • This question will interest more to a programming guy than to just a common computer guy,because a programming language have learnt about the jargon of data types,there sizes and there ranges but this ain't a question...question is do you know these terms are inter related to each other....huh??
    well if you don't then no problem read on and you'll find out,but if you do know that there is a connection but you don't know what it is...then too you're advised to read on and if you know everything then too you should read as you may find something more to it...
    This story leads by a character named "Character"
    Characters: There are 256 of them on which the processor can work..and the size of everyone of it is 1 byte and is usually denoted by a nick-name char..well many of you may know about that but do you know why they are only in a gang of 256..?
    This ain't simple, if you didn't know what permutation and combination is,But i will try to explain you that in the easiest way i know..
    As you know there are 8 bits in a byte,and the size of a character is set to be 1 byte i.e., 8 bits..Now think like this.
    As,there are 8 vacant places in the allotted size to a character which needs to be filled to complete a character and there are only two things which can be filled in these gaps which are 0(s) and 1(s).If below is the representation of the bit cells of a byte..
                                           
    then..,the no of ways by which the first and all of the rest cells can be filled are 2 (which are 0 and 1)..
    That is the first cell of a byte can be filled in these two ways,
                                         1 

                                         0 
    And so are the others.
    hence the total permutation(no.of ways these whole block of cells can be filled) are 2x2x2x2x2x2x2x2 = 28 = 256
    As the number of possible combinations which can be made by binaries in a character are only 256 that's why there are only this much no. of characters.
    So if you want to increase the no. of possible characters you have to increase the size which is allotted for a character (i.e., you need to allot 2,3 or some-other no.[any how] as required )...
    Similarly the number of numbers which can be saved in an integer data type are (2x2x2x2x2x2x2x2)x(2x2x2x2x2x2x2x2) = 216 = 65536 and range for that will be 0-65535.Because the size allocated for the int type = 2 bytes,which can be represented as follows in the form of cells.
                                                                                                

    Note :0-65535 is the range of an unsigned int i.e., an int data type which will only store positive numbers.for signed int the range will be defined when 65536 was split in to two for negative and positive numbers and then the range for that will be -32768 to 32767.
    Have a look at this table, for the reference of other data types..

          Data type             Size             Calculation              Result                Range          
    char121*8=282560 to 255
    unsigned int222*8=216655360 to 65535
    signed int2((22*8)/2)=((216)/2)32768-32768 to 32767
    long unsigned int424*8=23242949672960 to 4294967295


  • Now we will analyze the hexadecimal and octal numbers,especially it's conversion to binaries...
    see here is a table which represents hexadecimal conversion into it's binary form..
     hex no.  equivalent binary 
    00000
    10001
    20010
    30011
    40100
    50101
    60110
    70111
    81000
    91001
    A1010
    B1011
    C1100
    D1101
    E1110
    F1111
    Before beginning with anything i wanna tell you why this hexadecimal is called as hexa. Well it's simple it contains 16 characters,and 16 is usually prefixed as hex.
    Seeing and counting is not the only method to find the no. of characters in hexadecimal,you can also use the method we discussed earlier i.e, 2n method to calculate the number of hexadecimal possible.Here that n equals to 4.Hence 2n = 24 = 16 = total possible hexa's
    See there are two ways to remember this table.First is Pattern recognition method and the second one is Binary addition method.
    The Pattern

  • in this table is 1st column from left has 0 and 1 in alternate pattern and the 2nd column has two times zero and then two times one and the third it is.... So common formula which can be derived with the pattern is 2n*2 and n start from 0 and goes upto ((no. of total column)-1) and the distribution of it is in increasing order of column from left to right.
    And binary addition is the method in which we add 1 to every side of the to get next no. on the queue..
    Now, 0 was the first no. on hex side and 0000 in the binary side so adding 1 to both side we will get.
    1 on hex side and 0001 in the binary side but adding 1 further will get.
    2 on hex side but it won't result 0002 on the binary side because in binary there is no place for 2 so on adding 1 to 0001 it will become 0010 and on adding 1 again to it will make it 0011 and so on and so forth..
    Octal can also be drawn Similarly...but for the reference have a look at this table of it..
     hex no.  equivalent binary 
    0000
    1001
    2010
    3011
    4100
    5101
    6110
    7111
    Did you noticed the similarity in octal's and hex's table,well we have just removed the last column(when counted from left) and cut shorted the table's length(vertical length)
    I think this is more than enough for a post so we will be packing up for now..but you can ask any query anytime using the feature of comment or by messaging us at our facebook portal.

    1 comment:

    1. Nice explanation buddy
      finally i got rid of those butterflies

      ReplyDelete