This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Kubernetes in Action and have Marko Luksa on-line!
See this thread for details.
Win a copy of Kubernetes in Action this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 22968
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just use the writeByte() method.
 
Kah Tang
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!