Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Short range question  RSS feed

 
Tony Bateman
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

If I declare this, the compiler does not complain:

short m = -32768; //OK

In hexadecimal, 32768 is 8000.

If I declare this, the compiler gives an error:

short m = -0x8000; //possible loss of precision found: int,required: short

Why? The hexadecimal equivalent of 32768 IS 8000 hex.

This has got to be something to do with the sign bit.

What is the relationship with the hexadecimal format and the sign bit?

- Tony.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go back and double-check what you did, because this works just fine for me. What compiler are you using?
 
Tony Bateman
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I did; it still does!

I'm using Borland JBuilder X Foundation 1.0.0.176.0

Kind regards,

Tony.
 
Clay Adkerson
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It compiles fine in mine too. Im using JCreator.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess this is one more point in the "Why JBuilder sucks" column. That's simply incorrect behavior.
 
Tony Bateman
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK Thanks folks,

Guess it's never a good idea to place all of one's faith in the machine...

- Tony.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!