Which is equivalent to 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,a1,b1,a2,b2,a3,b3,a4,b4,a5,b5,a6,b6,a7,b7 - a8,b8,a9,b9,a10,b10,a11,b11,a12,b12,a13,b13,a14,b14,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 - unsigned long

this code is in "c". Now I have to implement this in java. Everything is fine when compiling and running the code. But here I used unsigned long and in java I used int. Since I work for 32 bits at a time. The problem is that "when implemented in java, whenever the result falls outside the range of int, the output is rejected, and this will not be the same output from C code. Is there any solution for my problem to replace unsigned long values range in java

+5
source share
3 answers

, java . long C 32- 32- , java long - 64-, ( , ). , BigInteger.

+9

- Java 8 Unsigned int long

Java, (, , int long) ( ).

Java Tutorial, Java SE 8 int, long unsigned.

int. int 32- , -2³¹ 2³¹-1. Java SE 8 int 32- , 0 2³²-1. Integer int . . " ". , compareUnsigned, divideUnsigned .., Integer .

long. - 64- . long -2⁶³ 2⁶³-1. Java SE 8 64- , 0 2⁶⁴-1. unsigned long 0 2⁶⁴-1. , , , int. long , compareUnsigned, divideUnsigned .. unsigned long.

. .

+17

Java . - , , BigInteger.

+4
source

All Articles