Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Java in General and the fly likes Overflow? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Overflow?" Watch "Overflow?" New topic


Dan Temple
Ranch Hand

Joined: Jul 10, 2001
Posts: 93
I have been using the JQ+ tester which has been worth every penny. However I have come across a question which seems wrong. But since they have been always right before, its probably me that's wrong. here is the question:
If write(0xAABBCCDD) is called on an instance of FileOutputStream, what will be written to the destination of the stream?
They say the answer is -
The byte 0xDD
But this seems wrong: Here is my reasoning, A Byte can only have a max value of 127 and DD is 221 in hex. In binary this is 11011101. Only the low order bits would be retained for a byte which is 1011101 which is 93, or 5D in hex. What am I missing?
Geoffrey Falk
Ranch Hand

Joined: Aug 17, 2001
Posts: 171
The byte 0xDD in decimal is -35 (a valid value).

Sun Certified Programmer for the Java 2 Platform
Dan Temple
Ranch Hand

Joined: Jul 10, 2001
Posts: 93
Ah yes ... I forgot that high order bit. Thanks for the reply
I agree. Here's the link:
subject: Overflow?
It's not a secret anymore!