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

stupid question

 
Shlomo Hillel
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can I read unsigned long in java?
the db has:
4 byte numeric, total overall length in bytes of each record

I read it like this:
RecordLength = (database.readUnsignedShort() << 16) |
(database.readUnsignedShort());

But that is obviously wrong!
How can I do it?

Even if I can do it, how can one reserve a byte array [size], where size
is unsigned long? size must always be int!

S
 
Shlomo Hillel
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry, that is reading unsigned integer.
I cannot use shifts and store it in a long since shift works on int.

Can I just say i treat it as a signed number and reject record lengths above
(2**31 -1)?
S
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
4 bytes is 32 bits, and that's an int in Java. (or is that what you meant in your second post?). Anyway, I would treat it as signed, accept only positive values and note the fact in my choices document. Considering the range of positive values of a int, it makes sense to me to do that.
[ June 23, 2006: Message edited by: Barry Gaunt ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic