下面这段代码想转换成java写 该怎么转换 涉及到位操作 java里面移位自动转换成int
传入是是个字节 压缩后要得到六个字节三位 谁帮我写一下 谢谢
int cd_code(unsigned char *in , int inlen , int number, int psw, char ser_sign, char chk)
{
if(in==NULL)
return -1;
unsigned char *all = in;
number = number << 11;
psw = psw << 11;
all[0] = (number >> 24);
all[1] = (number >> 16)&0x00FF;
all[2] = ((number >> 8)&0x0000F8) | (psw >> 29);
all[3] = (psw >> 21) & 0xFF;
all[4] = ((psw >> 13) & 0xFF) ;
all[5] = ((psw >> 5) & 0xc0) | (ser_sign & 0x3F) ;
//chk 3bit
all[6] = (chk & 0x07) << 5 ;
if(all == NULL)
return -2;
if(inlen != 7)
return -3;
return 0;
}
传入是是个字节 压缩后要得到六个字节三位 谁帮我写一下 谢谢
int cd_code(unsigned char *in , int inlen , int number, int psw, char ser_sign, char chk)
{
if(in==NULL)
return -1;
unsigned char *all = in;
number = number << 11;
psw = psw << 11;
all[0] = (number >> 24);
all[1] = (number >> 16)&0x00FF;
all[2] = ((number >> 8)&0x0000F8) | (psw >> 29);
all[3] = (psw >> 21) & 0xFF;
all[4] = ((psw >> 13) & 0xFF) ;
all[5] = ((psw >> 5) & 0xc0) | (ser_sign & 0x3F) ;
//chk 3bit
all[6] = (chk & 0x07) << 5 ;
if(all == NULL)
return -2;
if(inlen != 7)
return -3;
return 0;
}
for (int i = 0; i < len; i++) {
result += ((value[i] >= 0 ? value[i] : value[i] & 0xFF) + 0) << (i * 8);
}intToByte
new byte[] {(byte)(value & 0xFF), (byte)((value >> 8) & 0xFF), (byte)((value >> 16) & 0xFF),
(byte)((value >> 24) & 0xFF)};献丑了。