returnValue = Integer.toHexString(accumulator).toUpperCase();
for (i=returnValue.length(); i<4; i++)
returnValue = '0' + returnValue;C++无法获得数组的长度啊

解决方案 »

  1.   

    用C写的。char* g(unsigned int a) {
        char k[] = "0123456789ABCDEF";
        char r[sizeof (a)*2];
        int i = 0;
        while (a != 0) {
            r[i++] = k[a % 16];
            a /= 16;
        }
        while (i < 4) {
            r[i++] = '0';
        }
        char* t = malloc(i + 1);
        int j = 0;
        while (j < i) {
            t[j++] = r[i - 1 - j];
        }
        t[i] = 0;
        return t;
    }
      

  2.   

    String getCRC(byte[] arg) {
    int i, accumulator, data, index;
    String returnValue = new String();
    accumulator = 0xffff;
    for (i=0; i<arg.length; i++) {
    data = arg[i];
    index = (accumulator >> 8) ^ data;
    accumulator = (accumulator << 8) ^ this.crcTable[index];
    }
    accumulator ^= 0xffff;
    returnValue = Integer.toHexString(accumulator).toUpperCase();
    for (i=returnValue.length(); i<4; i++)
    returnValue = '0' + returnValue;
    return returnValue;
    }