programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Tim Cooke
• Devaka Cooray
• Ron McLeod
• Jeanne Boyarsky
Sheriffs:
• Liutauras Vilda
• paul wheaton
• Junilu Lacar
Saloon Keepers:
• Tim Moores
• Stephan van Hulst
• Piet Souris
• Carey Brown
• Tim Holloway
Bartenders:
• Martijn Verburg
• Frits Walraven
• Himai Minh

# Confused in Chapter 3 - SCJP 5

Ranch Hand
Posts: 95
• Number of slices to send:
Optional 'thank-you' note:
Hi

I am using 'Sun Certified Programmer for Java 5 Study Guide' by Kathy Sierra and Bert Bates. I am confused by 2 points and would appreciate it if one of you guys could help me, see below..

1.
I am on page 185 in chapter 3.
There is an example;

long l = 130L;
byte b = (byte)l;
System.out.print("b is " + b);

The output is b is -126

130 would be 000010000010 as a long (more leading zeroes though )
When converted to byte which is a signed 8 bit integer i expected
10000010 ie remove everything except the lowest 8 bits = -2
but we get -126 which I think is 11111110 so how did that happen?

2. On page 177 / 178 there is a hex example
which the book correctly indicates will give -559035650.
Where did the -ve come from?

Thanks to anyone who can help,

Rors

Rory Lynch
Ranch Hand
Posts: 95
• Number of slices to send:
Optional 'thank-you' note:
OK

Page 187 explains confusion number1 perfectly.

Confusion number2 still outstanding though...

Greenhorn
Posts: 5
• Number of slices to send:
Optional 'thank-you' note:
Friend,
That's because, the value of 0xdeadcaf is 233495727 which is 1913987920 less than the Integer.MAX_VALUE(A constant holding the maximum value an int can have, 2^31-1=2147483647)
And, 0xdeadcafe which is actually 3735931646 is much bigger a value an int can hold.Defining that as a long tells this.

Regards
-KG

 Hey cool! They got a blimp! But I have a tiny ad: the value of filler advertising in 2021 https://coderanch.com/t/730886/filler-advertising