File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes UrlyBird question: How can I put 0XFF into a byte ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Reply Bookmark "UrlyBird question: How can I put 0XFF into a byte ?" Watch "UrlyBird question: How can I put 0XFF into a byte ?" New topic
Author

UrlyBird question: How can I put 0XFF into a byte ?

Eric Chou
Greenhorn

Joined: Jul 23, 2008
Posts: 20
Hi, everyone

Due to the instruction, I have to set a flag, which is just one byte in length, to indicate whether a record is valid or deleted.
As I know, a byte variable could only ranges in -128 to 127. However, the instruction asks me to use 0XFF (which is 255) as a "deleted record" flag. How can I put 0XFF into a byte variable ?

Thanks in advance for any replies

Eric Chou
Kah Tang
Ranch Hand

Joined: Sep 10, 2007
Posts: 58
Well, you can.. but it takes too much hacking in your code and that won't satisfy the maniac junior programmer that is going to work with your code.

The best way to do it is to use the readUnsignedByte() method that is in the RandomAccessFile class. This method actually returns an int, where you can compare your 0xFF byte with.
Eric Chou
Greenhorn

Joined: Jul 23, 2008
Posts: 20
Thank you, Kah Tang.
However, your solution does help me write 0XFF into a byte field. There is not method called "writeUnsignedByte()", do you have a better idea in writing data?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16479
    
    2

Just use the writeByte() method.
Kah Tang
Ranch Hand

Joined: Sep 10, 2007
Posts: 58
Originally posted by Eric Chou:
Thank you, Kah Tang.
However, your solution does help me write 0XFF into a byte field. There is not method called "writeUnsignedByte()", do you have a better idea in writing data?


Yeah.. as Paul said, the writeByte() method. This will write the lower 8 bits of the int to the stream.
[ July 28, 2008: Message edited by: Kah Tang ]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: UrlyBird question: How can I put 0XFF into a byte ?
 
Similar Threads
B&S - Delete Flag
Several questions about SCJD instructions
URLyBird requirements confusion
delete method in B & S
Read record indicator flag