编写一个函数,把一个char(1 char=16bits) 分解成连个byte(1byte=8bits)。
求高手指教!
public static void main(String[] args) throws UnsupportedEncodingException {
char a = 'a';
String s = Character.toString(a);
byte b[] = s.getBytes();
int c = b.length;
System.out.println(c);
for(int i = 0; i< b.length;i++){
System.out.println(b[i]);
}
}
我这样编写不对!
求高手指教!
public static void main(String[] args) throws UnsupportedEncodingException {
char a = 'a';
String s = Character.toString(a);
byte b[] = s.getBytes();
int c = b.length;
System.out.println(c);
for(int i = 0; i< b.length;i++){
System.out.println(b[i]);
}
}
我这样编写不对!
解决方案 »
- java运算符优先级
- ASCII码的Socket传输
- 请问高手:synchronized 与 static method的问题
- getContentPane().问题
- JTree新增节点的事件
- 高分求javapro杂志下载地址
- 如何在JInternalFrame中创建一个模态的JDialog???
- 求java访问sql server的简单查询例子代码。
- 求教:JAVA程序的发布问题,编译成.EXE文件后,拷贝到其他机器会出现……详细请进
- JNative动行时提示Unloading native library 'BargaingApply'
- 请教一个算法问题!
- 串口通讯问题,200分稍后奉上!
public class Test
{
public static void main(String[] args)
{
char c = 'a';
byte[] b = null;
try
{
b = new String(new char[]{c}).getBytes("UTF-16LE");
}
catch (Exception e)
{
System.exit(-1);
}
for (int i = 0; i < b.length; i++)
{
System.out.println(i + ":" + b[i]);
}
}
}
byte b[] = s.getBytes("UTF-16LE");
就能达到效果!