Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2011
    Posts
    2
    Rep Power
    0

    Question negative ASCII to hex

    I am reading a file (Its DICOM binary file..let it be)...i get ASCII value 32...it can be easily converted to its hex value 20 using numerous java programes that convert "ASCII to hex"... but sometimes i get following values in input file
    -32
    -116
    the problem is how to convert these type of(-ve) ASCII to hex...hex Value of dec -32 is 00 20 but the normal ascii to hex shows it 0x0E which is wrong...help

  2. #2
    2by4 is offline Banned
    Join Date
    Dec 2011
    Posts
    143
    Rep Power
    0

    Default Re: negative ASCII to hex

    First question is, "Is your file really ASCII?" If you are reading negative byte data values, I suspect it is not.

    It may be using an ANSI code page or UNICODE. If it is, it will contain values greater than 127 which will show up as negative if represented as a byte data type.

    -32 for example is 11100000 in binary which is 0xE0

    This is a valid ANSI or UNICODE code unit. It is not a valid ASCII code point.
    Last edited by 2by4; 12-13-2011 at 11:36 AM.

  3. #3
    Join Date
    Dec 2011
    Posts
    2
    Rep Power
    0

    Default Re: negative ASCII to hex

    ok then how to deal with it...means how to get 00 20 from -32?thnx for reply

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: negative ASCII to hex

    How are you actually doing this conversion?
    Should be simple to show us a demo using just a "byte b = -32" and converting that.
    At the moment I can't see what it is you;re actually doing.

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,321
    Rep Power
    25

    Default Re: negative ASCII to hex

    hex Value of dec -32 is 00 20 but the normal ascii to hex shows it 0x0E
    System.out.println(Integer.toHexString(-32)); // prints ffffffe0

Similar Threads

  1. help - Ascii to hex and hex to ascii conversion
    By rjagan in forum New To Java
    Replies: 8
    Last Post: 06-14-2011, 12:53 PM
  2. Negative,Positive and Zero
    By dipowo in forum New To Java
    Replies: 2
    Last Post: 04-04-2011, 05:49 AM
  3. Mod of Negative Numbers
    By Venny in forum New To Java
    Replies: 7
    Last Post: 01-28-2011, 05:32 AM
  4. Help with negative numbers
    By cela0811 in forum New To Java
    Replies: 2
    Last Post: 01-04-2011, 05:04 PM
  5. Byte value comes out negative
    By Bluefox815 in forum New To Java
    Replies: 1
    Last Post: 07-03-2010, 03:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •