Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: delete flag in data records

 
Hugh Johns
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my deleteRecord() implementation, I am setting the flag byte to 0xFF as outlined in the specification ie.e
dataFileStream.writeByte(0xFF);
Whe I try to check this flag in another method like readRecord() I am checking if the flag == 0xFF i.e.
flag = dataFileStream.readByte();
if(flag == 0xFF){
.....
}
Simple enough, but I am getting the flag is -1 after delete whereas 0xFF should be 255, Where am I going wroung here?.
Hugh
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To quote Jim Yingst in this thread
In Java, 0xFF means 255, and a byte has range -128 to 127 - that's why you can't just say
byte b = 0xFF;
But you can say
byte b = (byte) 0xFF;
or equivalently
byte b = -1;

Does that explain the issue?
Regards, Andrew
 
Hugh Johns
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew
Thank you for the advice, I had decided to go with -1, but was not sure if this was appropriate.
Hugh
 
bharat kumar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew,
In my deleteRecord() specification it states that,
2 byte flag. 01 implies valid record, 0x8000 implies deleted record
byte b21[]=new byte[2];
if (status) {
b21[0]=00;
b21[1]=01;
} else {
b21[0]=80;
b21[1]=00;
}
Here status represents a valid record or not
Is it correct?
thanks,
Bharat.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bharat
That looks like one way of handling it.
You might like to think about what two bytes are equal to, and decide whether you want to work with that data type instead of two bytes instead. It might not gain you anything though, so you might not want to.
Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic