# [ACCEPTED]-Definition of range of a data type-c

Score: 12

A data type is an abstraction that is applied to 61 a chunk of memory to see that piece of memory 60 as an area that can represent a value.

For 59 example, a single byte consists of 8 bits 58 of memory. In the following diagram, each 57 bit is represented by an underscore (`_`):

``````byte: _ _ _ _ _ _ _ _  <- 8 bits
``````

Since 56 we have 8 positions where we can input either 55 an `0` or `1` (as each memory bit can only be 54 set to an `on` or `off` state -- hence binary), so we can 53 have `2^8` or 256 combinations of distinct values 52 we can represent from the 8 bits.

This is 51 were the concept of range comes into play 50 -- how do we allocate those 256 combinations 49 of values to an usable range?

One way is 48 to take the first of the 256 combinations 47 as a `0`, and the final combination as `255`:

``````byte: 0 0 0 0 0 0 0 0  <- Represents a "0"
byte: 0 0 0 0 0 0 0 1  <- Represents a "1"

.. so on ..

byte: 1 1 1 1 1 1 1 0  <- Represents a "254"
byte: 1 1 1 1 1 1 1 1  <- Represents a "255"
``````

For 46 this data type, the range is from `0` to `255`. This 45 type is generally called an `unsigned byte`, as the values 44 it can represent is `unsigned` as it has no sign. Basically, it 43 is handled as if it were all positive numbers.

On 42 the other hand, since we have 256 combinations, what 41 if we assign half of them as postive numbers 40 while the other half is negative numbers? So, we 39 assign a positive or negative value to a 38 byte representation:

``````byte: 0 1 1 1 1 1 1 1  <- Represents a "127"
byte: 0 1 1 1 1 1 1 0  <- Represents a "126"

.. so on ..

byte: 0 0 0 0 0 0 0 1  <- Represents a "0"
byte: 0 0 0 0 0 0 0 0  <- Represents a "0"
byte: 1 1 1 1 1 1 1 1  <- Represents a "-1"

.. so on ..

byte: 1 0 0 0 0 0 0 1  <- Represents a "-127"
byte: 1 0 0 0 0 0 0 0  <- Represents a "-128"
``````

The above representation 37 is called a "two's complement" system, and 36 the table above has been adapted from the 35 Wikipedia article on two's complement.

With this type of representation, in the 34 same 8-bits, we could define a way to represent 33 a range of numbers from `-128` to `127`. This representation 32 is generally called a `signed byte`, because it is a 31 `byte` type that can have both positive and negative 30 representations of the number.

In comparing 29 `unsigned byte` and `signed byte`, their ranges are different:

``````unsigned byte :       0  -  255
signed byte   :    -128  -  127
``````

However, they 28 are both have 256 possible combinations 27 of values they can represent. They only 26 differ by the range of values they can represent. That's 25 the range of a data type.

Similarly, this 24 can be extended to `int`, `long`, `float`, `double` types as well. The 23 number of bits that are assigned to each 22 data type is different. For example:

``````int:  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _   <- 16 bits
long: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  <- 32 bits
``````

Note: The actual number of bits for each type, such as `int` and `long` can be implementation- and architecture-dependent, so the above chart is not necessarily true.

In the 21 above chart, the `int` type is represented by 20 16-bits, which is `2^16` or `65536` combinations of values 19 that it can represent. Again, like the `byte`, the 18 range of values can be all positives or 17 split into positive and negatives:

``````unsigned int  :       0  -  65535
signed int    :  -32768  -  32767
``````

(Again, `int` does not necessarily have to be 16-bits.)

Floating point types 16 such as `float` and `double` are also represented by a 15 bits in memory, but their data representation 14 differs from integer data types such as 13 `byte` and `int` in that they will store a value in 12 memory as binary fractions and exponents. Floating 11 point types also do have the concept of 10 ranges as well.

For the nitty-gritty details 9 about how floating point values are defined 8 and calculated in modern systems, please 7 refer to Wikipedia has an article on the IEEE-754.

Data ranges of a data type arises 6 from the combinations of values which can 5 be represented from the amount of memory 4 assigned for a single unit of the single 3 data type, and how those possible combinations 2 are assigned to actual values that they 1 represent.

Score: 6

Range means the maximum and minimum value 6 that can be stored inside the variable of 5 a given type. For example if you have unsigned 4 char and if we assume that the size of the 3 datatype is 8 bits then you can store values 2 ranging from 0 - 2^8-1 i.e. 0-255 inside 1 it.

Score: 3

Range of a variable

The range of a variable 13 is given as the difference between the highest 12 and lowest value that that variable can 11 hold. For example, the range of a signed 10 16-bit integer variable is -32,768 to +32,767. In 9 the case of an integer, the variable definition 8 is restricted to whole numbers only, and 7 the range will cover every number within 6 its range (including the maximum and minimum). However, for 5 other numeric types, such as floating point 4 numbers, the range only expresses the largest 3 and smallest number that may be stored - within 2 the range there will be many numbers that 1 cannot be represented.

From wikipedia

Score: 2

you should take a look at limits.h in your 2 standard include-path. there are the exact 1 ranges for your machine-type

Score: 2

Most types in C are machine dependant, so 10 you should look the limits.h provided by 9 your compiler for your architecture.

There's 8 also a manual way to check it, for ordinal 7 types:

• if unsigned: `min = 0, max = 2**(sizeof(type)*8)-1`
• if signed: min = `-2**(sizeof(type)*8-1), max = 2**(sizeof(type)*8-1)-1`

For the floating point values, you 6 can take a look to the IEEE 754 standard, as 5 it's the most common format used in nearly 4 all architectures.

EDIT:

The definition of 3 range is the difference between the max 2 and min values the type can hold. For ordinal 1 types it's `2**(sizeof(type)*8)`.

Score: 1

more about datatypes in c and their ranges: here

0

Score: 0

Range is the minimum to maximum value supported 2 for that datatype.

Integers in C are of `16-bit`.

Signed int will be 1 `-32768` to `32767` i.e. `(-2^15)` to `(2^15 -1)`

Unsigned int: `0 to 65535` i.e. `0 to (2^16)`

Score: 0

Range is the range of values an datatype 2 can use, defined between its minimum and 1 maximum values.

Score: 0
``````public class JavaApplication4 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

System.out.println("Byte->"+Byte.MAX_VALUE+" "+Byte.MIN_VALUE);
System.out.println("Short->"+Short.MAX_VALUE+" "+Short.MIN_VALUE);
System.out.println("Integer->"+Integer.MAX_VALUE+" "+Integer.MIN_VALUE);
System.out.println("long->"+Long.MAX_VALUE+" "+Long.MIN_VALUE);
System.out.println("float->"+Float.MAX_VALUE+" "+Float.MIN_VALUE);
System.out.println("Double->"+Double.MAX_VALUE+" "+Double.MIN_VALUE);

}
``````

}

0

More Related questions