Digital Computers store datas in zeroes and ones. Any data we want to represent are converted to binary equivalent (zeroes and ones) and stored in the memory. Let us say we have 33, the binary equivalent of 33 is 100001. 33 will be actually stored as 100001 internally. Similarly if we have a character 'A', the ASCII equivalent of that character is taken and it is then converted to the binary equivalent and stored.
But had a look at the variations in the number of digits in the binary equivalent ? 33 takes 6 characters (100001), but 23 takes 5 (10111), similarly the number of bits (binary digits) differ for each number. So to create uniformity and to make the system understand where a number/character starts and end, they have introduced something called padding of zeroes. We will have fixed number of bits, say 8. So every number will be stored as 8 bit binary number. That is 33 will be stored as 00100001 and 23 will be stored as 00010111. This makes the compiler easy to understand where it should start reading a number.
Ok, What can we do for storing characters whose ASCII equivalent is also a number and is stored as binary the same way as a number. Wont there be a contracdiction whether it is a character or number? How can we differentiate it is a number or a character ? This is the reason we have data types. We tell the compiler whatever stored in this memory location is a charcter, and whatever we store here is a number through data types.
Ok, But 8 bits can store only from 0 to 255 (from 00000000 to 11111111). What can we do for higher numbers? Ok we can increase the number of bits from 8 to 16 or 32 or 64 etc. But the problem of extending the number of bits required to store one number is, we have to append more and more zeroes thus wasting the memory. This is one of the reasons why we have variations in Primary Data types. Also we need to have something called, range of values each data types can store. If we use the correct data types, we can save memory.
Next post will explain the range of values that can be used by a data type.
But had a look at the variations in the number of digits in the binary equivalent ? 33 takes 6 characters (100001), but 23 takes 5 (10111), similarly the number of bits (binary digits) differ for each number. So to create uniformity and to make the system understand where a number/character starts and end, they have introduced something called padding of zeroes. We will have fixed number of bits, say 8. So every number will be stored as 8 bit binary number. That is 33 will be stored as 00100001 and 23 will be stored as 00010111. This makes the compiler easy to understand where it should start reading a number.
Ok, What can we do for storing characters whose ASCII equivalent is also a number and is stored as binary the same way as a number. Wont there be a contracdiction whether it is a character or number? How can we differentiate it is a number or a character ? This is the reason we have data types. We tell the compiler whatever stored in this memory location is a charcter, and whatever we store here is a number through data types.
Ok, But 8 bits can store only from 0 to 255 (from 00000000 to 11111111). What can we do for higher numbers? Ok we can increase the number of bits from 8 to 16 or 32 or 64 etc. But the problem of extending the number of bits required to store one number is, we have to append more and more zeroes thus wasting the memory. This is one of the reasons why we have variations in Primary Data types. Also we need to have something called, range of values each data types can store. If we use the correct data types, we can save memory.
Next post will explain the range of values that can be used by a data type.
1 comments:
I am unable to read articles online very often, but I’m glad I did today. This is very well written and your points are well-expressed. Please, don’t ever stop writing.
java代写
Post a Comment