Java Utililty Methods Bit Shift

List of utility methods to do Bit Shift

Description

The list of methods to do Bit Shift are organized into topic(s).

Method

intshift(int a, int b)
shift
if ((0 < b) && (b < 32)) {
    return a << b;
} else if ((-32 < b) && (b < 0)) {
    return a >> (-b);
} else if (b == 0) {
    return a;
} else if (b >= 32) {
    return 0;
...
intshift(int component, int shift)
Bit shifts a color component, loosing the less significant bits
return component >> shift;
longshift(int direction, long sq, int delta)
shift
long result = sq;
for (int i = 0; i < delta; i++) {
    result = shift(direction, result);
return result;
intshift(int length)
shift
int shift = 1;
int shifted = 2;
while (shifted <= length) {
    ++shift;
    shifted <<= 1;
return shift;
Stringshift(String string)
shift
StringBuilder builder = new StringBuilder();
final String[] strings = string.split("\n");
for (String s : strings) {
    builder.append("    ").append(s).append("\n");
return builder.toString();
byteshiftBits(byte b)
shift Bits
int upper = b << 4 & b1;
int lower = b >> 4 & b2;
return (byte) (upper | lower);
byteshiftByte(byte n, short shift)
shift Byte
if (shift > 0) {
    return (byte) (n << shift);
} else {
    return (byte) (n >> -shift);
charshiftCharacter(char c, int offset)
shift Character
return (char) (c + offset);
StringshiftDouble(Object o, double shift, String suffix)
shift Double
Double d = parseDouble(o);
d = d + shift;
return (String.format("%.1f", d) + suffix);
intshiftHorizontally(int inkX, int inkXWidth, int textWidth)
Returns a shift of 'x' coordinate in pixels in order to fit the logical extent horizontally
if ((inkX < 0) && (inkXWidth <= textWidth)) {
    return inkX;
if ((inkX + inkXWidth > textWidth) && (inkXWidth <= textWidth)) {
    return (inkX + inkXWidth - textWidth);
return 0;