src/share/classes/java/lang/Long.java

Print this page
rev 6091 : 7088952: Add size in bytes constant "BYTES" to primitive type wrapper types
Summary: Adds a constant BYTES to each of the primitive wrapper classes (Byte, Character, Double, Float, Integer, Long, Short) with the calculation Primitive.SIZE / Byte.SIZE already made.
Reviewed-by: smarks, darcy


1290         } else {
1291             if (compareUnsigned(dividend, divisor) < 0) // Avoid explicit check for 0 divisor
1292                 return dividend;
1293             else
1294                 return toUnsignedBigInteger(dividend).
1295                     remainder(toUnsignedBigInteger(divisor)).longValue();
1296         }
1297     }
1298 
1299     // Bit Twiddling
1300 
1301     /**
1302      * The number of bits used to represent a {@code long} value in two's
1303      * complement binary form.
1304      *
1305      * @since 1.5
1306      */
1307     public static final int SIZE = 64;
1308 
1309     /**








1310      * Returns a {@code long} value with at most a single one-bit, in the
1311      * position of the highest-order ("leftmost") one-bit in the specified
1312      * {@code long} value.  Returns zero if the specified value has no
1313      * one-bits in its two's complement binary representation, that is, if it
1314      * is equal to zero.
1315      *
1316      * @return a {@code long} value with a single one-bit, in the position
1317      *     of the highest-order one-bit in the specified value, or zero if
1318      *     the specified value is itself equal to zero.
1319      * @since 1.5
1320      */
1321     public static long highestOneBit(long i) {
1322         // HD, Figure 3-1
1323         i |= (i >>  1);
1324         i |= (i >>  2);
1325         i |= (i >>  4);
1326         i |= (i >>  8);
1327         i |= (i >> 16);
1328         i |= (i >> 32);
1329         return i - (i >>> 1);




1290         } else {
1291             if (compareUnsigned(dividend, divisor) < 0) // Avoid explicit check for 0 divisor
1292                 return dividend;
1293             else
1294                 return toUnsignedBigInteger(dividend).
1295                     remainder(toUnsignedBigInteger(divisor)).longValue();
1296         }
1297     }
1298 
1299     // Bit Twiddling
1300 
1301     /**
1302      * The number of bits used to represent a {@code long} value in two's
1303      * complement binary form.
1304      *
1305      * @since 1.5
1306      */
1307     public static final int SIZE = 64;
1308 
1309     /**
1310      * The number of bytes used to represent a {@code long} value in two's
1311      * complement binary form.
1312      *
1313      * @since 1.8
1314      */
1315     public static final int BYTES = SIZE / Byte.SIZE;
1316 
1317     /**
1318      * Returns a {@code long} value with at most a single one-bit, in the
1319      * position of the highest-order ("leftmost") one-bit in the specified
1320      * {@code long} value.  Returns zero if the specified value has no
1321      * one-bits in its two's complement binary representation, that is, if it
1322      * is equal to zero.
1323      *
1324      * @return a {@code long} value with a single one-bit, in the position
1325      *     of the highest-order one-bit in the specified value, or zero if
1326      *     the specified value is itself equal to zero.
1327      * @since 1.5
1328      */
1329     public static long highestOneBit(long i) {
1330         // HD, Figure 3-1
1331         i |= (i >>  1);
1332         i |= (i >>  2);
1333         i |= (i >>  4);
1334         i |= (i >>  8);
1335         i |= (i >> 16);
1336         i |= (i >> 32);
1337         return i - (i >>> 1);