1

this js code

function keygen( serial) {
 return parseInt(serial.replace(/-/g, ''), 16)
}
keygen("C6AD-0E40")

gives

3333230144

and this java code

private int keygens(String serial) {

        String s=serial.replaceAll("[-]", "");
     int dec=Integer.parseUnsignedInt(s,16);
                 return dec+dec+dec; //one dec give negative value wondering why !!
}
        System.out.print(keygens("C6AD-0E40"));

gives

1409755840

WHY ? , i need to get the same return value of js function

Appreciate any help

JDEV
  • 79
  • 8
  • 4
    `3_333_230_144` is bigger than `2_147_483_647` which is the largest possible `int` in java. Use `Long.parseUnsignedLong(String, int)` instead. – azurefrog Dec 20 '19 at 19:06
  • 1
    See https://stackoverflow.com/questions/3001836/how-does-java-handle-integer-underflows-and-overflows-and-how-would-you-check-fo for more details on integer overflow. – azurefrog Dec 20 '19 at 19:07
  • @azurefrog thank you so much for help, it worked – JDEV Dec 20 '19 at 19:21

0 Answers0