This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How to set the deleted record flag

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
 
There will be plenty of time to discuss your objections when and if you return. The cargo is this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic