Re: Binary to ASCII Question

From: Steve W. Jackson (stevewjackson_at_charter.net)
Date: 10/23/03


Date: Thu, 23 Oct 2003 16:33:33 -0500

In article <3f983d89$1_2@newspeer2.tds.net>,
 "dog" <dawgwannabe@yahoo.com> wrote:

>:Binary to ascii Question
>:
>:I pick a JPG a.jpg
>:
>:I read in it using ServletInputStream to a byte[] array
>:
>:bytes are, of course, signed one byte things
>:So if you got through the array you get int values between -127 and 127
>:
>:If you say
>:
>:String s = new String(byteArray)
>:char[] x = s.toCharArray();
>:
>:And then go through that away you get int values way above 256
>:
>:Why?
>:
>:Really just wondering. I would think it would translate each byte to the
>:unicode equal which is what I am trying to do. Okay that didn't work, but
>:what did it do? Anyeasy way to go from a JPG to unicode?
>:Do I add 128 to all the byte value of just knock of the sign? Or niether?

Have you read the API docs on this? You'll notice that the String
constructor that accepts a byte array specifically states that it
constructs a new String by decoding the specified array of bytes using
the platform's default charset. So if that array of bytes didn't come
from Unicode or other actual character data, then you probably shouldn't
logically expect the resulting String to have any meaningful content.

= Steve =

-- 
Steve W. Jackson
Montgomery, Alabama


Relevant Pages

  • Re: need analysis on downloaded javascript - security threat - threat.zip
    ... The Javascript tries a few things. ... javascript apparently stores text strings as unicode ... This part of the code creates a long string of do-nothing machine ... will use the overflowing data in the large array as its return code ...
    (comp.lang.javascript)
  • Re: SaveSetting and Unicode
    ... VB standard of ASCII outside and Unicode inside? ... Copy the UDT to a byte array with CopyMemory: ... Dim MyStr as String ... If you save characters you wont see any problem, ...
    (microsoft.public.vb.general.discussion)
  • Re: Conversion of byte array to cstring
    ... "feature" is that there is a CString constructor that will accept an 8-bit ... string and create an initialized CString, even if the CString is actually ... This ctor converts from ANSI to Unicode, so, even if you are ... // Point to next WCHAR in source array ...
    (microsoft.public.vc.mfc)
  • Re: Unicode to ASCII string conversion
    ... ascii byte array, and then the byte array back into a string, I still have ... Unicode, right? ...
    (microsoft.public.dotnet.languages.vb)
  • Image Link Still Not Work
    ... Just choose any .jpg. ... or something similar and display that .jpg if the file ... >It appears to work fine inputing the string into a text ... Roger had mentioned storing the path and then ...
    (microsoft.public.access.modulesdaovba)

Loading