Add byte to int conversion code
This commit is contained in:
parent
85c4162119
commit
84530dd8bb
|
@ -0,0 +1,25 @@
|
|||
package com.baeldung.bytetoint;
|
||||
|
||||
public class ByteToIntConversion {
|
||||
static int usingTypeCasting(byte b){
|
||||
int i = b;
|
||||
return i;
|
||||
}
|
||||
|
||||
static int usingIntegerValueOf(byte b){
|
||||
return Integer.valueOf(b);
|
||||
}
|
||||
|
||||
static int usingByteIntValue(byte b){
|
||||
Byte byteObj = new Byte(b);
|
||||
return byteObj.intValue();
|
||||
}
|
||||
|
||||
static int usingMathToIntExact(byte b){
|
||||
return Math.toIntExact(b);
|
||||
}
|
||||
|
||||
static int usingByteUnsignedInt(byte b){
|
||||
return Byte.toUnsignedInt(b);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue