how to read 16 - bit values?

R

Rajesh.Rapaka

HI all,

I guess I am lost with all the fundamentals and all logical thinking.
plz help me.

I am using java. and I have an 16-bit image file. but this image file
contains of integer values ( in 16-bit). now using java how can i read
the 16-bit signed integer value ??

plz help !!
I know this should be a very very simple question. but failed to think
or find a gateway at this last moment.

kindly help
regards,
Rajesh RApaka.
 
F

foo

Do the following until you have read all bytes. File should have even
bytes.
Assumption is that while writing the high byte was written before the
low byte. If it's not true exchange b0 and b1 in line 3 and 5 of the
code.

short s = 0;
byte b0 = in.read(); byte b1 = in.read();
s = s | b0;
s << 8;
s = s | b1;
 
G

Greg Stark

Also, consider using the DataInputStream class instead. Or perhaps
ByteBuffer might be more appropriate?
 
R

Rajesh.Rapaka

this what I did !! But somehow it wrked very differently!! I guess i'll
check my codes again.

regards,
Rajesh Rapaka
 
B

bugbear

Rajesh.Rapaka said:
HI all,

I guess I am lost with all the fundamentals and all logical thinking.
plz help me.

I am using java. and I have an 16-bit image file. but this image file
contains of integer values ( in 16-bit). now using java how can i read
the 16-bit signed integer value ??

Hmm Input. File. That might lead one to look in the java.io package.

java.io.DataInputStream

A data input stream lets an application read primitive Java data
types > from an underlying input stream in a machine-independent way.

HTH.

BugBear
 
L

Lee Ryman

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hmm Input. File. That might lead one to look in the java.io package.

java.io.DataInputStream

Your not, are you? You couldn't actually be suggesting someone reads the
API documentation? Don't you know that is utter madness? Do you not
realise the consequences of encouraging people to start reading API
docs? The constant flux of stupid newsgroup questions stemming from the
lack of common-sense is critical not only to the necessary daily
expression of sarcasm and wit by gurus (required to maintain the
inflation of their heads), but for the stability of our universe and the
space-time continuum. It is people like you with outrages implication
such as the necessity to RTFM before posting that will lead to the
downfall of society, the destruction of Earth, the Big-Crunch, and (god
give me the courage to mention it) actually _good_ software!

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iEYEARECAAYFAkJyJbQACgkQhbcFpQga0LDkYwCgvxawwv1MFxdx8PcBzHlQUOlB
aS8AoIftIresPXPk1jCHDDs7Zt5hivos
=620R
-----END PGP SIGNATURE-----
 
B

bugbear

Lee said:
Your not, are you? You couldn't actually be suggesting someone reads the
API documentation? Don't you know that is utter madness? Do you not
realise the consequences of encouraging people to start reading API
docs? The constant flux of stupid newsgroup questions stemming from the
lack of common-sense is critical not only to the necessary daily
expression of sarcasm and wit by gurus (required to maintain the
inflation of their heads), but for the stability of our universe and the
space-time continuum. It is people like you with outrages implication
such as the necessity to RTFM before posting that will lead to the
downfall of society, the destruction of Earth, the Big-Crunch, and (god
give me the courage to mention it) actually _good_ software!

<<chuckle>>

BugBear
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top