Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

what readUnsignedByte() will return in this case ?

Status
Not open for further replies.

sergeiY

Programmer
Feb 13, 2003
132
AU
Hi

I am helping a friend to prepare for Java exam (uni) and threre is this question that I don't know answer for...

FileInputStream fis;
DataInputStream dis;

int value1, value2;

fis = new FileInputStream("file.dat");
dis = newDataInputStream(fis);

value1 = dis.readUnsignedByte();
value2 = dis.readShort();

if 'file.dat' contains the byte values, F1 F2 F3 04 F5 06 F7 08 What is contained in value1 and value2 after execution?

I looked up what readUnsignedByte does ... it reads the next byte of this input stream, interpreted as an unsigned 8-bit number

but what is a next byte in this case ??? how many characters, 8 ??

same with readShort() it reads next two bytes of this input stream, interpreted as a signed 16-bit number what this will do ???

Thank you in advance for your help
 
well i assume DataInputStream.readUnsignedByte will increment the file pointer, in which case you will read the first two bytes. value1 will contain 11110001 read as an unsigned byte (241 if my sums are right), and value2 will contain 11110010 read as a short... unfortunatly i'm not sure how java stors a short. it's probably two's compliment, i'm sure you can track down the relevent information.

wish your friend good luck.
 
what exam is your friend taking? 1.4. I took it and there is no questions related to I/O. In java 1.2., yes there is.

~za~
You can't bring back a dead thread!
 
thank you all for your input I passed it back to my friend and it helped

she is doing Undegraduate Uni course in Internet & Multimidia Programming
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top