-1

I have a ""binary"" string String s1 = "10011000" and want to print the corresponding Character (Ф) of this Byte, how can I make this?

I have read and tested so many solutions and tutorials...and can't find exactly what I want! Moreover, I think therected is an encoding problem.

For example, this code doesn't work, but why (I have "?" in output, so encoding problem?)?

int j = Integer.parseInt("10011000", 2);    
System.out.println(new Character ((char)j));
J0e3gan
  • 8,740
  • 10
  • 53
  • 80
night
  • 1
  • 1
  • 1
    Do you know what's decimal form of 10011000? Also what's the ascii value of that decimal number? So what's your requirement and expectation? – SMA Nov 15 '14 at 16:53
  • The `?` is the representation of the character in your console. Just try another bit string or iterate trough. – Hannes Nov 15 '14 at 16:56
  • possible duplicate of [Converting binary data to characters in java](http://stackoverflow.com/questions/8634527/converting-binary-data-to-characters-in-java) – Christian Strempfer Nov 15 '14 at 16:59
  • 1
    possible duplicate of [How to convert Strings to and from UTF8 byte arrays in Java](http://stackoverflow.com/questions/88838/how-to-convert-strings-to-and-from-utf8-byte-arrays-in-java) – Nir Alfasi Nov 15 '14 at 17:01
  • possible duplicate of [Binary to text in Java](http://stackoverflow.com/questions/4211705/binary-to-text-in-java) – Christian Strempfer Nov 15 '14 at 17:11
  • possible duplicate of [Convert binary string to ascii text?](http://stackoverflow.com/questions/5453017/convert-binary-string-to-ascii-text) – Christian Strempfer Nov 15 '14 at 17:12
  • possible duplicate of [Parsing a string of binary into text/characters](http://stackoverflow.com/questions/6222526/parsing-a-string-of-binary-into-text-characters) – Christian Strempfer Nov 15 '14 at 17:13
  • possible duplicate of [Encoding to use to convert Bytes array to String and vice-versa](http://stackoverflow.com/questions/7996955/encoding-to-use-to-convert-bytes-array-to-string-and-vice-versa) – Christian Strempfer Nov 15 '14 at 17:33

3 Answers3

1

10011000 is unicode code point 152 which is an extended unicode character which will only appear if its encoding is supported by your console

Reimeus
  • 158,255
  • 15
  • 216
  • 276
  • Humm .. Ok, so, they are no solutions for, when i make a System.out.println, display this "special chars" ? – night Nov 15 '14 at 17:10
  • The character you are attempting to display does not appear to be displayable in the Eclipse console. The correct unicode code point for the character youre looking for is `1060` or `10000100100` as indicated by @Mariusz Nosiński's answer :) – Reimeus Nov 15 '14 at 17:14
  • In fact, i have a project where i must parse random binary string (of 8 bits, so one Byte per String) to a string with corresponding character of each strings. And certain character doesnt' display like real character, so it's blocking for the next .. – night Nov 15 '14 at 17:28
1

The character Ф is a Cyrillic capital letter; in Unicode, the hexadecimal value is \u0424. The binary string you are trying to parse is 152 decimal. The binary string for \u0424 is 010000100100 (1060 decimal) and so I would fix that first. And as others noted, until your environment character set supports Unicode output, Java will substitute a "?" character for any character that the current character set doesn't support. See Unicode characters in Eclipse for setting up Eclipse console to Unicode.

Community
  • 1
  • 1
Mark Stewart
  • 2,046
  • 4
  • 22
  • 32
0

You have used wrong code. If you want to see in output Ф you need to change your code into this:

int j = Integer.parseInt("10000100100", 2);
System.out.println((char) j);
Mariusz Nosiński
  • 1,308
  • 9
  • 10
  • I always have "?" in output ! In fact, i have a project where i must parse random binary string (of 8 bits, so one Byte per String) to a string with corresponding character of each strings. – night Nov 15 '14 at 17:25