As far as I know, there is no ready-made Java function that allows you to do this in a row, perhaps because it is something relatively simple.
Just in case, I went to confirm Jon Skeet spoke on the subject, and at least in 2011 there was no.
You can implement it yourself:
public class ByteInt {
public static void main(String[] args) {
byte[] bytes = new byte[]{1, 2, 3, 4, (byte) 130}; //exemplo
int[] sin = converteByteSinalizadoParaInt(bytes);
int[] naoSin = converteByteNaoSinalizadoParaInt(bytes);
System.out.println("Sinalizados");
for(int s: sin) {
System.out.println(s);
}
System.out.println("\nNão Sinalizados");
for(int ns: naoSin) {
System.out.println(ns);
}
}
public static int[] converteByteSinalizadoParaInt(byte[] entrada) {
int[] sin = new int[entrada.length];
for(int i =0; i<entrada.length; i++) {
sin[i] = entrada[i];
}
return sin;
}
public static int[] converteByteNaoSinalizadoParaInt(byte[] entrada) {
int[] naoSin = new int[entrada.length];
for(int i =0; i<entrada.length; i++) {
naoSin[i] = entrada[i] & 0xff;
}
return naoSin;
}
}
Exit:
Signposted
1
2
3
4
-126
Unmarked
1
2
3
4
130
If I understand correctly do
for(int i=0; i < dataRegCodeToCompare.length; i++){vetor[i] = dataRegCodeToCompare[i];}
– ramaral
That’s right @ramaral thank you so much!
– kaamis