Re: Binary to ASCII Question

From: Marco Schmidt (marcoschmidt_at_geocities.com)
Date: 10/23/03


Date: Thu, 23 Oct 2003 23:15:43 +0200

dog:

[...]

>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?

Not sure what you are trying to accomplish here. Why would you want to
convert the binary data of a JPEG file to a character stream?

You can convert bytes to int values in the interval 0..255 by using
the & operator:

byte b = ...;
int i = b & 0xff;

Same with char:

char c = b & 0xff;

If you really use the String constructor, some of the original bytes
may get converted to other values because the default character
encoding of the JVM running may require a conversion.

The question remains: Why do you want the binary data as a character
array or String?

Regards,
Marco

-- 
Please reply in the newsgroup, not by email!
Java programming tips: http://jiu.sourceforge.net/javatips.html
Other Java pages: http://www.geocities.com/marcoschmidt.geo/java.html


Relevant Pages

  • Re: what if (f)printf returns EINTR ?
    ... vsnprintf - formatted output conversion ... int fprintf; ... write to the character string str. ...
    (comp.unix.programmer)
  • Proposal: String::Format::General
    ... It provides format string parsing and output assembly, you provide the code that implements the individual conversion characters. ... Format syntax is kind of a cross between sprintf and strftime, but how close it is to each of these depends on the semantics implemented by the user. ... Note that the following is pre-alpha documentation; the interface to the output conversion code has changed since yesterday, ... conversion character, and contain a number of optional fields which may ...
    (comp.lang.perl.modules)
  • Re: question abt fscanf
    ... >I belive tht data in file is stored as ascii character constants i.e ... The scanf engine obeys the directives given in the format string. ... introduces a conversion, the 'l' modifier, and the 'd' conversion ... and convert a "long int" rather than a plain int, ...
    (comp.lang.c)
  • Re: Character KIND conversion?
    ... One thing I noticed is the lack of a CHARACTER kind conversion function, even though there are such functions for all other intrinsic types, including LOGICAL. ... Which, of course, is only guaranteed to work for characters in the ASCII data set. ... Interestingly, the Fortran-95 ISO-VARYING-STRING standard does define one, for converting between the varying strings and normal fortran strings; it's an overload to the CHARfunction. ...
    (comp.lang.fortran)
  • Re: queries about sprintf
    ... > promotion to do. ... Decisions based upon the format string's contents are made at ... first element containing the wint_t argument to the lc conversion ... specification and the second a null wide character." ...
    (comp.std.c)