List of usage examples for java.lang Byte intValue
public int intValue()
From source file:Main.java
public static void main(String[] args) { Byte byteObject = new Byte("10"); int i = byteObject.intValue(); System.out.println("int:" + i); }
From source file:Main.java
public static void main(String[] args) { Byte bObj = new Byte("10"); byte b = bObj.byteValue(); System.out.println(b);//w w w . j av a 2s. c o m short s = bObj.shortValue(); System.out.println(s); int i = bObj.intValue(); System.out.println(i); float f = bObj.floatValue(); System.out.println(f); double d = bObj.doubleValue(); System.out.println(d); long l = bObj.longValue(); System.out.println(l); }
From source file:Main.java
public static String byte2HexString(byte[] bytes) { String ret = ""; if (bytes != null) { for (Byte b : bytes) { ret += String.format("%02X", b.intValue() & 0xFF); }/*from ww w .j a v a 2 s. c om*/ } return ret; }
From source file:Main.java
/** * Convert an array of bytes into a string of hex values. * //from ww w.j a va 2 s . c om * @param bytes Bytes to convert. * @return The bytes in hex string format. */ public static String byte2HexString(byte[] bytes) { String ret = ""; for (Byte b : bytes) { ret += String.format("%02X", b.intValue() & 0xFF); } return ret; }
From source file:Main.java
public static int[] byte2int(byte[] src, int height, int width) { int dstLength = src.length; int[] dst = new int[dstLength]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { Byte b = new Byte(src[height * (143 - j) + i]); dst[(width * i) + j] = b.intValue() & 0x000000ff; if (dst[(width * i) + j] < 0) { System.out.println(dst[(width * i) + j]); }/*from w w w. j a va 2 s . co m*/ } } return dst; }
From source file:com.pfarrell.crypto.HmacUtil.java
/** * toHexes the given bytes array, and returns it. * @param buf input byte buffer//from www . j av a 2 s .com * @return hexified result */ public static String hexify(byte[] buf) { Preconditions.checkNotNull(buf); StringBuilder sb = new StringBuilder(); for (int i = 0; i < buf.length; i++) { Byte b = new Byte(buf[i]); String s = Integer.toHexString(b.intValue()); if (s.length() == 1) s = "0" + s; if (s.length() > 2) s = s.substring(s.length() - 2); sb.append(s); } return sb.toString(); }
From source file:wwutil.jsoda.DataUtil.java
/** Caller should handle custom valueType first before calling this. * E.g. DynamoDB's Set<String> and Set<long> fields are encoded as Multi-Value AttributeValue. */// w w w . j a v a 2 s. co m @SuppressWarnings("unchecked") static String encodeValueToAttrStr(Object value, Class valueType) { if (value == null) return null; // Caller needs to handle null correctly, e.g. skip storing AttributeValue. if (valueType == String.class) return value.toString(); // NOTE: Don't change encoding and padding once data have been created. Different encoding will mess up sorting. // Stringify basic type and encode them for sorting. if (valueType == Byte.class || valueType == byte.class) { Byte casted = (Byte) ConvertUtils.convert(value, Byte.class); return SimpleDBUtils.encodeZeroPadding(casted.intValue(), 3); // 0-Padded for sorting } else if (valueType == Short.class || valueType == short.class) { Short casted = (Short) ConvertUtils.convert(value, Short.class); return SimpleDBUtils.encodeZeroPadding(casted.intValue(), 5); // 0-Padded for sorting } else if (valueType == Integer.class || valueType == int.class) { Integer casted = (Integer) ConvertUtils.convert(value, Integer.class); return SimpleDBUtils.encodeZeroPadding(casted.intValue(), 10); // 0-Padded for sorting } else if (valueType == Long.class || valueType == long.class) { Long casted = (Long) ConvertUtils.convert(value, Long.class); return SimpleDBUtils.encodeZeroPadding(casted.longValue(), 19); // 0-Padded for sorting } else if (valueType == Float.class || valueType == float.class) { Float casted = (Float) ConvertUtils.convert(value, Float.class); return SimpleDBUtils.encodeZeroPadding(casted.floatValue(), 16); // 0-Padded for sorting } else if (valueType == Double.class || valueType == double.class) { // SimpleDBUtils has no padding for double. Just convert it to String. return value.toString(); } else if (valueType == Boolean.class || valueType == boolean.class) { return value.toString(); } else if (valueType == Character.class || valueType == char.class) { return value.toString(); } else if (valueType == Date.class) { return SimpleDBUtils.encodeDate((Date) value); } else if (valueType.isEnum()) { return ((Enum) value).name(); } // JSONify the rest. return toJson(value); }
From source file:com.google.gsa.valve.saml.SAMLArtifactProcessor.java
/** * Generate a random Hex for creating the artifact * /*from www .ja v a2 s . c o m*/ * @param size artifact size * * @return random number */ public static String createRandomHexString(int size) { byte[] bytes = new byte[size]; randomGenerator.nextBytes(bytes); StringBuilder sb = new StringBuilder(bytes.length * 2); for (int i = 0; i < bytes.length; i++) { Byte aByte = new Byte(bytes[i]); int intVal = Math.abs(aByte.intValue()); sb.append(Integer.toHexString(intVal)); } return sb.toString(); }
From source file:com.github.jessemull.microflex.util.IntegerUtil.java
/** * Safely converts a number to an integer. Loss of precision may occur. Throws * an arithmetic exception upon overflow. * @param Object number to parse/*from w ww . j a v a 2 s. co m*/ * @return parsed number * @throws ArithmeticException on overflow */ public static int toInteger(Object obj) { /* Switch on class and convert to an int */ String type = obj.getClass().getSimpleName(); int parsed; switch (type) { case "Byte": Byte by = (Byte) obj; parsed = by.intValue(); break; case "Short": Short sh = (Short) obj; parsed = sh.intValue(); break; case "Integer": Integer in = (Integer) obj; parsed = in.intValue(); break; case "Long": Long lo = (Long) obj; if (!OverFlowUtil.intOverflow(lo)) { throw new ArithmeticException("Overflow casting " + obj + " to an int."); } parsed = lo.intValue(); break; case "Float": Float fl = (Float) obj; if (!OverFlowUtil.intOverflow(fl)) { throw new ArithmeticException("Overflow casting " + obj + " to an int."); } parsed = fl.intValue(); break; case "BigInteger": BigInteger bi = (BigInteger) obj; if (!OverFlowUtil.intOverflow(bi)) { throw new ArithmeticException("Overflow casting " + obj + " to an int."); } parsed = bi.intValue(); break; case "BigDecimal": BigDecimal bd = (BigDecimal) obj; if (!OverFlowUtil.intOverflow(bd)) { throw new ArithmeticException("Overflow casting " + obj + " to an int."); } parsed = bd.intValue(); break; case "Double": Double db = (Double) obj; if (!OverFlowUtil.intOverflow(db)) { throw new ArithmeticException("Overflow casting " + obj + " to an int."); } parsed = db.intValue(); break; default: throw new IllegalArgumentException( "Invalid type: " + type + "\nData values " + "must extend the abstract Number class."); } return parsed; }
From source file:com.github.jessemull.microflex.util.IntegerUtil.java
/** * Safely converts a number to an integer. Loss of precision may occur. Throws * an arithmetic exception upon overflow. * @param Number number to parse//from w ww .j a v a2 s . com * @return parsed number * @throws ArithmeticException on overflow */ public static int toInteger(Number number) { /* Switch on class and convert to an int */ String type = number.getClass().getSimpleName(); int parsed; switch (type) { case "Byte": Byte by = (Byte) number; parsed = by.intValue(); break; case "Short": Short sh = (Short) number; parsed = sh.intValue(); break; case "Integer": Integer in = (Integer) number; parsed = in.intValue(); break; case "Long": Long lo = (Long) number; if (!OverFlowUtil.intOverflow(lo)) { throw new ArithmeticException("Overflow casting " + number + " to an int."); } parsed = lo.intValue(); break; case "Float": Float fl = (Float) number; if (!OverFlowUtil.intOverflow(fl)) { throw new ArithmeticException("Overflow casting " + number + " to an int."); } parsed = fl.intValue(); break; case "BigInteger": BigInteger bi = (BigInteger) number; if (!OverFlowUtil.intOverflow(bi)) { throw new ArithmeticException("Overflow casting " + number + " to an int."); } parsed = bi.intValue(); break; case "BigDecimal": BigDecimal bd = (BigDecimal) number; if (!OverFlowUtil.intOverflow(bd)) { throw new ArithmeticException("Overflow casting " + number + " to an int."); } parsed = bd.intValue(); break; case "Double": Double db = (Double) number; if (!OverFlowUtil.intOverflow(db)) { throw new ArithmeticException("Overflow casting " + number + " to an int."); } parsed = db.intValue(); break; default: throw new IllegalArgumentException( "Invalid type: " + type + "\nData values " + "must extend the abstract Number class."); } return parsed; }