1 19 20 package jxl.biff; 21 22 25 public final class IntegerHelper 26 { 27 30 private IntegerHelper() 31 { 32 } 33 34 41 public static int getInt(byte b1, byte b2) 42 { 43 int i1 = ((int) b1) & 0xff; 44 int i2 = ((int) b2) & 0xff; 45 int val = i2 << 8 | i1; 46 return val; 47 } 48 49 56 public static short getShort(byte b1, byte b2) 57 { 58 short i1 = (short) (b1 & 0xff); 59 short i2 = (short) (b2 & 0xff); 60 short val = (short) (i2 << 8 | i1); 61 return val; 62 } 63 64 65 74 public static int getInt(byte b1, byte b2, byte b3, byte b4) 75 { 76 int i1 = getInt(b1, b2); 77 int i2 = getInt(b3, b4); 78 79 int val = i2 << 16 | i1; 80 return val; 81 } 82 83 89 public static byte[] getTwoBytes(int i) 90 { 91 byte[] bytes = new byte[2]; 92 93 bytes[0] = (byte) (i & 0xff); 94 bytes[1] = (byte) ((i & 0xff00) >> 8); 95 96 return bytes; 97 } 98 99 105 public static byte[] getFourBytes(int i) 106 { 107 byte[] bytes = new byte[4]; 108 109 int i1 = i & 0xffff; 110 int i2 = (i & 0xffff0000) >> 16; 111 112 getTwoBytes(i1, bytes, 0); 113 getTwoBytes(i2, bytes, 2); 114 115 return bytes; 116 } 117 118 119 127 public static void getTwoBytes(int i, byte[] target, int pos) 128 { 129 byte[] bytes = getTwoBytes(i); 130 target[pos] = bytes[0]; 131 target[pos + 1] = bytes[1]; 132 } 133 134 142 public static void getFourBytes(int i, byte[] target, int pos) 143 { 144 byte[] bytes = getFourBytes(i); 145 target[pos] = bytes[0]; 146 target[pos + 1] = bytes[1]; 147 target[pos + 2] = bytes[2]; 148 target[pos + 3] = bytes[3]; 149 } 150 } 151 | Popular Tags |