Of course you can explicitly cast the >127 values to keep the compiler's
mouth shut:byte[] array= { (byte)0xff, (byte)0x80, 0x7f, 0x00 };
kind regards,
Jos
> > > Jos - Kaj : 1 - 0 :-P
> >
> > Don't you mean
> >
> > 11111111 - 10000001 ;)
>
> That would still make it
>
> -1 and -127.So mathematically Jos's score is bigger :D
That was the point :)
OK guys, thanks for the zeros-ones-game. Good dribbling.
My colluege got back from lunch and told me that byte alwas get "converted" to ints. Hmm, lots to learn in the basics.
Thanks for you help, I will spread my dukes among you :-)
I casted it to (byte) and the problem will be solved...
/Helena
> My colluege got back from lunch and told me that byte alwas get
> "converted" to ints. Hmm, lots to learn in the basics.
It's a bit more subtle than that. Given a binary expression "L op R" where
L and R are both operands to the operator "op". If both L and R are
narrower than (or equal to) an int, both operand types will be cast to ints.
This casting is performed by using sign extension, i.e. the sign bit of
the originial type will be used for all the bits in the wider type.
If one of the types is wider than an int, e.g. a long, strange things can
happen if you don't pay attention. Have a look at this example:int x= 0x7fffffff;
int y= 0x7fffffff;
long z= 2;
System.out.println(x+y+z);
System.out.println(x+(y+z));
> Thanks for you help, I will spread my dukes among you :-)
Thanks for the duke thingies.
kind regards,
Jos