how to read 16 - bit values?

Discussion in 'Java' started by Rajesh.Rapaka, Apr 28, 2005.

  1. 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.
    Rajesh.Rapaka, Apr 28, 2005
    #1
    1. Advertising

  2. Rajesh.Rapaka

    foo Guest

    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;
    foo, Apr 28, 2005
    #2
    1. Advertising

  3. Rajesh.Rapaka

    Greg Stark Guest

    Also, consider using the DataInputStream class instead. Or perhaps
    ByteBuffer might be more appropriate?
    Greg Stark, Apr 28, 2005
    #3
  4. this what I did !! But somehow it wrked very differently!! I guess i'll
    check my codes again.

    regards,
    Rajesh Rapaka
    Rajesh.Rapaka, Apr 29, 2005
    #4
  5. Rajesh.Rapaka

    bugbear Guest

    Rajesh.Rapaka wrote:
    > 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
    bugbear, Apr 29, 2005
    #5
  6. Rajesh.Rapaka

    Lee Ryman Guest

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    bugbear wrote:
    >
    > 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-----
    Lee Ryman, Apr 29, 2005
    #6
  7. Rajesh.Rapaka

    bugbear Guest

    Lee Ryman wrote:
    >
    >
    > 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
    bugbear, Apr 29, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    1,714
    Timothy Bendfelt
    Jan 19, 2007
  2. Replies:
    4
    Views:
    313
    Old Wolf
    Jul 3, 2005
  3. Read 16-bit block as a 32-bit int

    , Mar 28, 2007, in forum: C Programming
    Replies:
    2
    Views:
    541
    Stephen Sprunk
    Mar 28, 2007
  4. Replies:
    9
    Views:
    938
    Juha Nieminen
    Aug 22, 2007
  5. Jeff.M
    Replies:
    6
    Views:
    162
    Lasse Reichstein Nielsen
    May 4, 2009
Loading...

Share This Page