What is the equivalent of unsigned long in Java

I wrote the following three functions for my project:

WORD shuffling(WORD x)
{

// WORD - 4 bytes - 32 bits

//given input - a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15- b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15

//output required - a0,b0,b7 - a8,a15,b15

    x = (x & 0X0000FF00) << 8 | (x >> 8) & 0X0000FF00 | x & 0XFF0000FF;
    x = (x & 0X00F000F0) << 4 | (x >> 4) & 0X00F000F0 | x & 0XF00FF00F;
    x = (x & 0X0C0C0C0C) << 2 | (x >> 2) & 0X0C0C0C0C | x & 0XC3C3C3C3;
    x = (x & 0X22222222) << 1 | (x >> 1) & 0X22222222 | x & 0X99999999;
    return x;
}

WORD t_function(WORD n)
{

    WORD t_result=0;
    WORD64 var = 2*((n*n)& 0xFFFFFFFF)+n;   // (n*n mod FFFFFFFF) becomes a 32-bit word
    t_result = (WORD) ((var)& 0xFFFFFFFF);
    return t_result;
}

WORD lfsr(WORD t_result)
{

    WORD returnValue = t_result;
    WORD flag = 0;
    flag = returnValue & 0x80000000; // Checking if MSB is 1 or 0

    // Left shift the input
    returnValue = returnValue << 1;

    // If MSB is 1 then XOR the reult with the primitive polynomial
    if(flag > 0)
    {
        returnValue = returnValue ^ 0x4C11DB7;
    }
    return returnValue;
}

Word – unconditional long

This code is located in "C" Now I have to implement it in Java Everything is fine when compiling and running the code But here I use unsigned long and in Java I use int because I only run 32 bits at a time The question is "when the implementation result in Java exceeds the range of int, the output is deviated, and it will not be the same output of C code. Is there any way to solve my problem to replace the unsigned long range value in Java

Solution

In short, there are no unsigned data types in Java In C, C is 32 bits on a 32-bit system, but Java is 64 bits long, so you can replace it (at least it can solve the overflow problem) If you need a wider integer, use the BigInteger class

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>