1 package org.simantics.db.procore.cluster;
\r
3 final class BitUtility {
\r
4 static final long LongBits = 64;
\r
5 static final int IntBits = 32;
\r
6 static final short ShortBits = 16;
\r
7 static final long ClearHighIntMask = (1L << IntBits) - 1;
\r
8 static final long ClearLowIntMask = -1l ^ ClearHighIntMask;
\r
9 static final long ClearHighShortMask = (1L << ShortBits) - 1;
\r
10 static final long ClearLowShortMask = -1L ^ ClearHighShortMask;
\r
12 static final int getHighInt(long longValue) {
\r
13 return (int) (longValue >>> IntBits);
\r
16 static final long setHighInt(long longValue, int highValue) {
\r
17 longValue = (longValue & ClearHighIntMask) | (long) highValue << IntBits;
\r
21 static final int getLowInt(long longValue) {
\r
22 return (int) longValue;
\r
25 static final long setLowInt(long longValue, int lowValue) {
\r
26 longValue = (longValue & ClearLowIntMask) | lowValue;
\r
30 static final long setLowAndHighInt(long longValue, int lowValue, int highValue) {
\r
31 longValue = ((long) lowValue & ClearHighIntMask) | ((long) highValue << IntBits);
\r
35 static final short getLowShort(long longValue) {
\r
36 return (short)longValue;
\r
39 static final long setLowShort(long longValue, short lowValue) {
\r
40 longValue = (longValue & ClearLowShortMask) | (lowValue & ClearHighShortMask);
\r
44 static final int getMiddle(final long longValue, final int skip, final int size) {
\r
45 return (int)(longValue >>> skip) & (1<<size)-1;
\r
48 static final long setMiddle(long longValue, final int skip, final int size, int value) {
\r
49 long a1 = (1L<<size)-1;
\r
50 long m1 = (a1 << skip);
\r
51 long mask = -1L ^ m1;
\r
52 long t1 = (value & a1) << skip;
\r
53 long t2 = longValue & mask;
\r