java - Long type Integer calculation -


i making source code calculates long integers, don't know why calculation gives me wrong answer.

long l; //variable l input long, signed int  l *= 0x6869l; if(l == 0xeaaeb43e477b8487l)     system.out.println("correct!"); 

i did 0xeaaeb43e477b8487 / 0x6869 = 0xffffcbbb6d375815 when calculate 0xffffcbbb6d375815 * 0x6869 gives 0xeaaeb43e477ba89d.

why thing happens? , real answer of math question?

this because when divide 0xeaaeb43e477b8487l / 0x6869 lose remainder, causes loss of precision.

0xeaaeb43e477b8487l % 0x6869= -9238 

if take account get

0xeaaeb43e477ba89dl -9238 =  0xeaaeb43e477b8487 

this works

if ((l - 9238) == 0xeaaeb43e477b8487l)     system.out.println("correct!"); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -