Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { private final static long MAX_UNSIGNED_INT_VALUE = 4294967296L; public static int ulongToInt(long value) { if (value <= MAX_UNSIGNED_INT_VALUE) { if (value >= MAX_UNSIGNED_INT_VALUE / 2) { return (int) (~(MAX_UNSIGNED_INT_VALUE - value) + 1); } else { return (int) value; } } else { throw new IllegalArgumentException("Value out of range for a int"); } } }