What does this exactly mean? The size of a data type dictates the range of values that can be assigned to a variable of that type.
A quick and easy example to understand that is the following: The data type byte for example is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive) Therefore the size of the byte data type dictates what values it can hold.
If you could only use one digit for a number, you could have 10 values, 0 - 9. If you could use two digits, you could have 100 values, 0 - 99. Same principle with bytes. A byte is 8 binary digits. A binary digit can have a value of either 0 or 1, hence the binary. With 8 bits (BInary DigiTs), you could have 256 values, 0 - 255. Two bytes, or 16 bits, 65,536 ( 256 * 256 ) possible values, 0 - 65535. Four bytes, 32 bit, a bit over 4 billion possible values. Eight bytes, 64 bit is something like 15 quadrillion possible values.
@Chris2332 Thanks but next time would you mind explaining why -127 to 127 ... I am lucky for I study those things and understand that is it under the binary numeric system.
This is because as we said the byte data type is 8-bit signed integer. This means tha you have 7 byte positions to describe your number in binary form and one (the left most) to describe the sign of your number. 127 will give you the binary 1111111 (that's 7 ones) and the first byte will be 0 (for positive) while -128 will be 0000000(that's 7 zeros) and the first byte will be 1 (for negative). Does that make sense now?
I know it but thanks for answering by the way.
Join our real-time social learning platform and learn together with your friends!