W
W
wartemw2017-04-07 18:14:17
Java
wartemw, 2017-04-07 18:14:17

Question about an array of byte?

there is an array of byte ((3 235) , (225 7)).
according to the int principle (this is 2 byte).
how to convert a byte array to an int to get ((1003) , (2017))?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
ruslanys, 2017-04-13
@wartemw

int is 4 bytes, not 2.
But you can add like this:

int i = 0;

byte b1 = 3; // 11
byte b2 = 5; // 101

i = i | b1;
i = i << 8;
i = i | b2;

System.out.println(i);

Just be aware that there are no unsigned types in Java, so `byte b = 235` cannot be).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question