• Post Reply Bookmark Topic Watch Topic
  • New Topic
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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to set the deleted record flag

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear all:
According to my assignment, I have got two byte flag field and I should set 0x8000 to imply deleted record. Could any one give me an idea how I could create a two byte array which hold the 0x8000 please!

Thank you very much.
 
Ranch Hand
Posts: 759
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
0x8000 is 32768 right ? 2 byte array means it is short, the max value of short is 32767, so for the deleted record, the short value is -32768. So if you want to mark a record to deleted record, just point the RandomAccessFile to the flag, and use its writeShort(-32768) method. Please consider the other's opinion before use my solution. Thanks


Hope that helps

Jeffry Kristianto Yanuar (Java Instructor)
SCJP 5.0, SCJA, SCJD (UrlyBird 1.3.2) --> Waiting for the result
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that Jeffry's approach would work, but I suggest there might be a more intuitive approach. If the goal is to set two bytes to 0x8000 then why not just do a .writeShort(0x8000)?

The objective is to set the highest order bit of a two byte field. When doing bit operations it seems advisable to keep to a bit oriented numeric base such as hexadecimal or octal. Of course decimal will work, but it isn't always intuitive when doing bit manipulations and can become more problematic when two's complement numbers come into play.
 
Zonglin Li
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jeffry and Tom:
Thank you very much for your reply.

I think the method which you mentioned is a correct way. But I would like to follow Andrew Monkhouse�s DVD example to create a string with all the field�s values together (including the flag field) and write it together. So I need create a flag field string (two bytes with 0x8000). Do you have any idea how could I possibly do this please?

Cheers
 
Jeffry Kristianto Yanuar
Ranch Hand
Posts: 759
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Li, my assigment is URLyBird, I create Hotel object but I didn't include the flag. I only include the Hotel's field. Regarding the flag, I put in the class whic access to the database. The choice is yours. make sure you document your decision.

Jeffry Kristianto Yanuar (Java Instructor)
SCJP 5.0, SCJA, SCJD (UrlyBird 1.3.2) --> Waiting for the result
reply
    Bookmark Topic Watch Topic
  • New Topic