vijaya vinayagam

Greenhorn

Posts: 21

posted 11 years ago

Hi,

is there any limit for the number of digits to be used while assiging values to the variables ??

Eg.

int a = 564646464646535336667447774477

let me know that for each literal and for each way of representing that like (octal,hexa)

and give an examplefor that tooooo

thanks in advance

bye

is there any limit for the number of digits to be used while assiging values to the variables ??

Eg.

int a = 564646464646535336667447774477

let me know that for each literal and for each way of representing that like (octal,hexa)

and give an examplefor that tooooo

thanks in advance

bye

Jeff Albertson

Ranch Hand

Posts: 1780

posted 11 years ago

Here's a suggestion that will serve you well in Java, and life: try it out! What happens when you write that line in a program?

Originally posted by vijaya vinayagam:

Hi,

is there any limit for the number of digits to be used while assiging values to the variables ??

Eg.

int a = 564646464646535336667447774477

Here's a suggestion that will serve you well in Java, and life: try it out! What happens when you write that line in a program?

There is no emoticon for what I am feeling!

Stuart Ash

Ranch Hand

Posts: 637

posted 11 years ago

While you can't try out what happens if you build the top storeys of a building without building the foundation, you can certainly try out most things in software. Thus, there should be no reason why one should not try out such stuff and then come here to discuss the whys and wherefores.

Originally posted by Jeff Albrechtsen:

Here's a suggestion that will serve you well in Java, and life: try it out! What happens when you write that line in a program?

While you can't try out what happens if you build the top storeys of a building without building the foundation, you can certainly try out most things in software. Thus, there should be no reason why one should not try out such stuff and then come here to discuss the whys and wherefores.

ASCII silly question, Get a silly ANSI.

Shyam Prasad Murarka

Ranch Hand

Posts: 209

posted 11 years ago

Dear Readers,

This is a table of

byte -128 to 127

short -32,768 to 32,767

int -2,147,483,648 to 2,147,483,647

long -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

float -3.402823e38 to 3.402823e38

double -1.79769313486232e308 to 1.79769313486232e308

char Symbols used in text eg. 'A'

boolean True or False

I would appreciate it if my mistakes are corrected.

This is a table of

**Data Types**with their range of values:**Type****Value**byte -128 to 127

short -32,768 to 32,767

int -2,147,483,648 to 2,147,483,647

long -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

float -3.402823e38 to 3.402823e38

double -1.79769313486232e308 to 1.79769313486232e308

char Symbols used in text eg. 'A'

boolean True or False

I would appreciate it if my mistakes are corrected.

With Best Regards,

Shyam Prasad Murarka

Jeff Albertson

Ranch Hand

Posts: 1780

Ilja Preuss

author

Sheriff

Sheriff

Posts: 14112

posted 11 years ago

Why does this feel like a homework question to me?

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus

Stan James

(instanceof Sidekick)

Ranch Hand

Ranch Hand

Posts: 8791

Tom Sullivan

Ranch Hand

Posts: 72

posted 11 years ago

Well, here's a recap of what your textbook should be telling you.

As Shyam's post indicates, range limits are not simply a "number of digits." Instead, the first thing to consider is the amount of

NUMERIC INTEGRALS...

byte: 8 bits

short: 16 bits

int: 32 bits

long: 64 bits

NUMERIC FLOATING POINT...

float: 32 bits

double: 64 bits

SPECIAL CASES...

char: 16 bits

boolean: 1 bit

Once you know this, the next step is to understand how values are represented in binary for each type.

In Java,

Let's consider byte as an example. A byte is 8 bits, and 8 zeros represents a value of zero: 00000000. The positive values are straightforward binary...

0 => 00000000

1 => 00000001

2 => 00000010

3 => 00000011

...

126 => 01111110

127 => 01111111

For negative values, consider what -1 should look like in binary. When we add +1 to it, we should get zero. So -1 is represented by all ones: 11111111. (Thus, -1 + 1 is 11111111 + 00000001 = 00000000.)

In general, "increasing" the binary representation of a negative value moves that value towards zero. So the minimum negative value is a one followed by all zeros. In the case of byte, this is 10000000, representing -128...

-128 => 10000000

-127 => 10000001

-126 => 10000010

...

-2 => 11111110

-1 => 11111111

Therefore, the range of an 8-bit byte is -128 to 127, which is

Notice that the range of positive values is one less than the range of negative values because zero is

Ranges for the other numeric integral types follow this same pattern.

Floating-point values are stored quite differently, according to a standard called "IEEE 754." This is a topic unto itself (best addressed by searching the web for "IEEE 754"), but some key points are as follows. As with the integral numerics, floating-point numerics use the leading bit to indicate the sign. The remaining bits store the value in a scientific notation format, with an "exponent" value and a "mantissa" value. This provides for tremendous range with a "sliding window" of precision. For this reason, floating-point values should be considered

A 16-bit char is much like an integral primitive, except that its values are all non-negative. Thus, the numeric range for a char is

Finally, a single-bit boolean is restricted to values of true or false.

As Shyam's post indicates, range limits are not simply a "number of digits." Instead, the first thing to consider is the amount of

*memory*that each type is allotted.NUMERIC INTEGRALS...

byte: 8 bits

short: 16 bits

int: 32 bits

long: 64 bits

NUMERIC FLOATING POINT...

float: 32 bits

double: 64 bits

SPECIAL CASES...

char: 16 bits

boolean: 1 bit

Once you know this, the next step is to understand how values are represented in binary for each type.

In Java,

*all numeric primitive types are signed,*meaning that they can represent both positive and negative values. The first bit is sometimes called the "sign bit." If this is 1, then the value is negative. If it's 0, then the value is non-negative.Let's consider byte as an example. A byte is 8 bits, and 8 zeros represents a value of zero: 00000000. The positive values are straightforward binary...

0 => 00000000

1 => 00000001

2 => 00000010

3 => 00000011

...

126 => 01111110

127 => 01111111

For negative values, consider what -1 should look like in binary. When we add +1 to it, we should get zero. So -1 is represented by all ones: 11111111. (Thus, -1 + 1 is 11111111 + 00000001 = 00000000.)

In general, "increasing" the binary representation of a negative value moves that value towards zero. So the minimum negative value is a one followed by all zeros. In the case of byte, this is 10000000, representing -128...

-128 => 10000000

-127 => 10000001

-126 => 10000010

...

-2 => 11111110

-1 => 11111111

Therefore, the range of an 8-bit byte is -128 to 127, which is

**-2^7 to (-2^7) - 1.**Notice that the range of positive values is one less than the range of negative values because zero is

*non-negative*(having a leading bit of of 0).Ranges for the other numeric integral types follow this same pattern.

Floating-point values are stored quite differently, according to a standard called "IEEE 754." This is a topic unto itself (best addressed by searching the web for "IEEE 754"), but some key points are as follows. As with the integral numerics, floating-point numerics use the leading bit to indicate the sign. The remaining bits store the value in a scientific notation format, with an "exponent" value and a "mantissa" value. This provides for tremendous range with a "sliding window" of precision. For this reason, floating-point values should be considered

*approximations.*(See this thread for a more detailed illustration, this page for a nice explanation, and bookmark the essential, Some things you should know about floating-point arithmetic.)A 16-bit char is much like an integral primitive, except that its values are all non-negative. Thus, the numeric range for a char is

**0 to (2^16) - 1.**How these values translate to symbols is another topic. (For most common characters, see this ACSII table.)Finally, a single-bit boolean is restricted to values of true or false.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." *~Joe Strummer*

sscce.org

It is sorta covered in the JavaRanch Style Guide. |