1522 */ 1523 public static int signum(long i) { 1524 // HD, Section 2-7 1525 return (int) ((i >> 63) | (-i >>> 63)); 1526 } 1527 1528 /** 1529 * Returns the value obtained by reversing the order of the bytes in the 1530 * two's complement representation of the specified {@code long} value. 1531 * 1532 * @return the value obtained by reversing the bytes in the specified 1533 * {@code long} value. 1534 * @since 1.5 1535 */ 1536 public static long reverseBytes(long i) { 1537 i = (i & 0x00ff00ff00ff00ffL) << 8 | (i >>> 8) & 0x00ff00ff00ff00ffL; 1538 return (i << 48) | ((i & 0xffff0000L) << 16) | 1539 ((i >>> 16) & 0xffff0000L) | (i >>> 48); 1540 } 1541 1542 /** use serialVersionUID from JDK 1.0.2 for interoperability */ 1543 private static final long serialVersionUID = 4290774380558885855L; 1544 } | 1522 */ 1523 public static int signum(long i) { 1524 // HD, Section 2-7 1525 return (int) ((i >> 63) | (-i >>> 63)); 1526 } 1527 1528 /** 1529 * Returns the value obtained by reversing the order of the bytes in the 1530 * two's complement representation of the specified {@code long} value. 1531 * 1532 * @return the value obtained by reversing the bytes in the specified 1533 * {@code long} value. 1534 * @since 1.5 1535 */ 1536 public static long reverseBytes(long i) { 1537 i = (i & 0x00ff00ff00ff00ffL) << 8 | (i >>> 8) & 0x00ff00ff00ff00ffL; 1538 return (i << 48) | ((i & 0xffff0000L) << 16) | 1539 ((i >>> 16) & 0xffff0000L) | (i >>> 48); 1540 } 1541 1542 /** 1543 * Adds two {@code long} values together as per the + operator. 1544 * 1545 * @param a the first operand 1546 * @param b the second operand 1547 * @return the sum of {@code a} and {@code b} 1548 * @see java.util.function.BinaryOperator 1549 * @since 1.8 1550 */ 1551 public static long sum(long a, long b) { 1552 return a + b; 1553 } 1554 1555 /** 1556 * Returns the greater of two {@code long} values. 1557 * 1558 * @param a the first operand 1559 * @param b the second operand 1560 * @return the larger of {@code a} and {@code b} 1561 * @see java.util.function.BinaryOperator 1562 * @since 1.8 1563 */ 1564 public static long max(long a, long b) { 1565 return Math.max(a, b); 1566 } 1567 1568 /** 1569 * Returns the lesser of two {@code long} values. 1570 * 1571 * @param a the first operand 1572 * @param b the second operand 1573 * @return the lesser of {@code a} and {@code b} 1574 * @see java.util.function.BinaryOperator 1575 * @since 1.8 1576 */ 1577 public static long min(long a, long b) { 1578 return Math.min(a, b); 1579 } 1580 1581 /** use serialVersionUID from JDK 1.0.2 for interoperability */ 1582 private static final long serialVersionUID = 4290774380558885855L; 1583 } |