/**
* Convert string to bytes for Chinese and other two-byte characters
*/
public static byte[] stringToBytes(String ss)
{
ssLen = ss.length();
cc = ss.toCharArray();
ssBuffer = new byte[ssLen*2];
for(i=0;i<ssLen;i++)
{
ssBuffer[i*2+1] = (byte)cc[i];
ssBuffer[i*2] = (byte)((int)cc[i]>>8);
}
return ssBuffer;
} /**
* Convert bytes to string for Chinese and other two-byte characters
*/
public static String bytesToString(byte[] ssBuffer, int offset, int length)
{
ssLen = (length&0xff)/2;
cc = new char[ssLen];
for(i=0;i<ssLen;i++)
{
cc[i] = (char)(((ssBuffer[offset+i*2] & 0xff) << 8) | (ssBuffer[offset+i*2+1] & 0xff));
}
return new String(cc);
// return new String(ssBuffer,offset,length);
}
* Convert string to bytes for Chinese and other two-byte characters
*/
public static byte[] stringToBytes(String ss)
{
ssLen = ss.length();
cc = ss.toCharArray();
ssBuffer = new byte[ssLen*2];
for(i=0;i<ssLen;i++)
{
ssBuffer[i*2+1] = (byte)cc[i];
ssBuffer[i*2] = (byte)((int)cc[i]>>8);
}
return ssBuffer;
} /**
* Convert bytes to string for Chinese and other two-byte characters
*/
public static String bytesToString(byte[] ssBuffer, int offset, int length)
{
ssLen = (length&0xff)/2;
cc = new char[ssLen];
for(i=0;i<ssLen;i++)
{
cc[i] = (char)(((ssBuffer[offset+i*2] & 0xff) << 8) | (ssBuffer[offset+i*2+1] & 0xff));
}
return new String(cc);
// return new String(ssBuffer,offset,length);
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货