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