Forums Register Login

question about long

+Pie Number of slices to send: Send

As i try to add a f behind 0xffffffff,the compiler response a error,int is out of range.
right,because int has 32 bits. the output is right .
11111111111111111111111111111111

as i try to add a f behind 0xffffffff,the compiler response a error too,int is out of range.
why does compiler look 0xfffffff as a int?
the output is 1111111111111111111111111111111111111111111111111111111111111111.
since 0xffffffff has 32bits,why the output has 64bits "1"?

the output is right 1111111111111111111111111111111111111111111111111111111111111111.
thanks a lot!

1
+Pie Number of slices to send: Send
Hard coded integer type values are considered by the compiler to be ints unless you tell it otherwise. If you add an 'L' to the right hand end the compiler will consider it to be a long ie:
+Pie Number of slices to send: Send
Thanks for your help!
Hard coded integer type values are considered by the compiler to be ints unless you tell it otherwise.

output:
11111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111
why the second is
1111111111111111111111111111111111111111111111111111111111111111
not
11111111111111111111111111111111
the hexadecimal value are equal,but the output are not equal. why?
1
+Pie Number of slices to send: Send
You are not assigning a long to the second number. You are assigning an int. Remember all integer literals are unsigned, so you can write 0xffff_ffff as if it were a positive number, but it represents -1.
Now you are assigning the int value -1 to your long; it undergoes widening conversion to -1L. And -1L is sixty‑four 1 bits.
If you want to keep it as thirty‑two 1 bits, you would have to write 0xffff_ffffL. You can only use the _ character in Java7.
+Pie Number of slices to send: Send
I see。
thanks Campbell Ritchie and Tony Docherty。
I can't beleive you just said that. Now I need to calm down with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 751 times.
Similar Threads
Manipulating Hex Integers
fyi: pre/post increment with exception thrown on the line
exponent loop w/out math .pow.
casting
TIJ 3 problem at simpeltest
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 09:59:24.