# Thread: negative ASCII to hex

1. Member
Join Date
Dec 2011
Posts
2
Rep Power
0

## 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. Banned
Join Date
Dec 2011
Posts
143
Rep Power
0

## 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 12:36 PM.

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

## Re: negative ASCII to hex

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

4. Moderator
Join Date
Apr 2009
Posts
13,331
Rep Power
23

## 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. ## 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

#### Posting Permissions

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