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 * Suitable for conversion as a method reference to functional interfaces such
1545 * as {@code BinaryOperator<Long>} or {@code LongBinaryOperator}.
1546 *
1547 * @param a an argument.
1548 * @param b another argument.
1549 * @return the sum of {@code a} and {@code b}.
1550 * @since 1.8
1551 */
1552 public static long sum(long a, long b) {
1553 return a + b;
1554 }
1555
1556 /**
1557 * Returns the greater of two {@code long} values.
1558 * Suitable for conversion as a method reference to functional interfaces such
1559 * as {@code BinaryOperator<Long>} or {@code LongBinaryOperator}.
1560 *
1561 * @param a an argument.
1562 * @param b another argument.
1563 * @return the larger of {@code a} and {@code b}.
1564 * @since 1.8
1565 */
1566 public static long max(long a, long b) {
1567 return (a >= b) ? a : b;
1568 }
1569
1570 /**
1571 * Returns the lesser of two {@code long} values.
1572 * Suitable for conversion as a method reference to functional interfaces such
1573 * as {@code BinaryOperator<Long>} or {@code LongBinaryOperator}.
1574 *
1575 * @param a an argument.
1576 * @param b another argument.
1577 * @return the lesser of {@code a} and {@code b}.
1578 * @since 1.8
1579 */
1580 public static long min(long a, long b) {
1581 return (a <= b) ? a : b;
1582 }
1583
1584 /** use serialVersionUID from JDK 1.0.2 for interoperability */
1585 private static final long serialVersionUID = 4290774380558885855L;
1586 }
|