将0和1的字符串转换为另一个字符串

时间:2014-04-09 16:19:26

标签: java

我有一个0和1的字符串。我想通过一次取8个字符并将其转换为二进制的Integer,然后将此Integer转换为字符,将此字符串转换为另一个字符串。

代码:

String s2="";
String s="10000111";
char nextChar;
for(int i = 0; i < s.length(); i += 8) 
{
     nextChar = (char)Integer.parseInt(s.substring(i, i+8), 2);
     System.out.println(nextChar);
     s2 += nextChar;
}

如果我将它作为一个简单的java文件运行,代码会给出正确的答案,但是当我在Web应用程序中运行它时,它会给出奇怪的结果。为什么会这样,以及如何让Web应用程序产生相同的结果?

在桌面应用程序中:

http://postimg.org/image/ww88p3ot5/

在网络应用程序中:

(在浏览器中)

135, 
31, 
120,x 
27, 
192,À 
242,ò 
146, 
128, 
255,ÿ 
14, 
11, 
107,k 
159, 

(在输出屏幕上)

http://postimg.org/image/ydn9h9nsf/

0 个答案:

没有答案