Convert hexadecimal byte array to int [closed]











up vote
0
down vote

favorite












I read 4 hexadecimal bytes from input stream into an array on server side from client, f.e. x00x00x02x24 which is 224 in hex. I need to convert it into an int. How could this be done?










share|improve this question













closed as unclear what you're asking by ruakh, sleske, GBlodgett, Matthew L Daniel, Devon_C_Miller Nov 11 at 5:43


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.















  • I'm missing something. It sounds like your input is just new byte { 0, 0, 2, 36 }; but there's nothing "hexadecimal" about that (other than that you've chosen to write it as x00x00x02x24 for some reason in the text of the question itself). Can you clarify?
    – ruakh
    Nov 10 at 21:31










  • I'm sorry that's as much as I know. I'm not sure how to check it, the program I'm writing does also other tasks with multiple threads at once.
    – David Bulko
    Nov 10 at 22:09















up vote
0
down vote

favorite












I read 4 hexadecimal bytes from input stream into an array on server side from client, f.e. x00x00x02x24 which is 224 in hex. I need to convert it into an int. How could this be done?










share|improve this question













closed as unclear what you're asking by ruakh, sleske, GBlodgett, Matthew L Daniel, Devon_C_Miller Nov 11 at 5:43


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.















  • I'm missing something. It sounds like your input is just new byte { 0, 0, 2, 36 }; but there's nothing "hexadecimal" about that (other than that you've chosen to write it as x00x00x02x24 for some reason in the text of the question itself). Can you clarify?
    – ruakh
    Nov 10 at 21:31










  • I'm sorry that's as much as I know. I'm not sure how to check it, the program I'm writing does also other tasks with multiple threads at once.
    – David Bulko
    Nov 10 at 22:09













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I read 4 hexadecimal bytes from input stream into an array on server side from client, f.e. x00x00x02x24 which is 224 in hex. I need to convert it into an int. How could this be done?










share|improve this question













I read 4 hexadecimal bytes from input stream into an array on server side from client, f.e. x00x00x02x24 which is 224 in hex. I need to convert it into an int. How could this be done?







java






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 21:26









David Bulko

74




74




closed as unclear what you're asking by ruakh, sleske, GBlodgett, Matthew L Daniel, Devon_C_Miller Nov 11 at 5:43


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as unclear what you're asking by ruakh, sleske, GBlodgett, Matthew L Daniel, Devon_C_Miller Nov 11 at 5:43


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • I'm missing something. It sounds like your input is just new byte { 0, 0, 2, 36 }; but there's nothing "hexadecimal" about that (other than that you've chosen to write it as x00x00x02x24 for some reason in the text of the question itself). Can you clarify?
    – ruakh
    Nov 10 at 21:31










  • I'm sorry that's as much as I know. I'm not sure how to check it, the program I'm writing does also other tasks with multiple threads at once.
    – David Bulko
    Nov 10 at 22:09


















  • I'm missing something. It sounds like your input is just new byte { 0, 0, 2, 36 }; but there's nothing "hexadecimal" about that (other than that you've chosen to write it as x00x00x02x24 for some reason in the text of the question itself). Can you clarify?
    – ruakh
    Nov 10 at 21:31










  • I'm sorry that's as much as I know. I'm not sure how to check it, the program I'm writing does also other tasks with multiple threads at once.
    – David Bulko
    Nov 10 at 22:09
















I'm missing something. It sounds like your input is just new byte { 0, 0, 2, 36 }; but there's nothing "hexadecimal" about that (other than that you've chosen to write it as x00x00x02x24 for some reason in the text of the question itself). Can you clarify?
– ruakh
Nov 10 at 21:31




I'm missing something. It sounds like your input is just new byte { 0, 0, 2, 36 }; but there's nothing "hexadecimal" about that (other than that you've chosen to write it as x00x00x02x24 for some reason in the text of the question itself). Can you clarify?
– ruakh
Nov 10 at 21:31












I'm sorry that's as much as I know. I'm not sure how to check it, the program I'm writing does also other tasks with multiple threads at once.
– David Bulko
Nov 10 at 22:09




I'm sorry that's as much as I know. I'm not sure how to check it, the program I'm writing does also other tasks with multiple threads at once.
– David Bulko
Nov 10 at 22:09












1 Answer
1






active

oldest

votes

















up vote
1
down vote













Shift and sum them (as it done in DataInputStream#readInt())



byte bytes = {0, 0, 0x2, 0x24};
int i = ((bytes[0] << 24) + (bytes[1]<< 16) + (bytes[2]<< 8) + (bytes[3] << 0));
System.out.println(i);


Output:



548



Maybe you're looking for DataInputStream?



byte bytes = {0, 0, 0x2, 0x24};
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(bytes));
System.out.println(inputStream.readInt());


Output:



548






share|improve this answer























  • I'm lookimg for something like this, only shouldn't 224 hex be 548 decimal?
    – David Bulko
    Nov 10 at 21:55










  • @DavidBulko yes, 0x224 = 548
    – caco3
    Nov 10 at 22:00


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













Shift and sum them (as it done in DataInputStream#readInt())



byte bytes = {0, 0, 0x2, 0x24};
int i = ((bytes[0] << 24) + (bytes[1]<< 16) + (bytes[2]<< 8) + (bytes[3] << 0));
System.out.println(i);


Output:



548



Maybe you're looking for DataInputStream?



byte bytes = {0, 0, 0x2, 0x24};
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(bytes));
System.out.println(inputStream.readInt());


Output:



548






share|improve this answer























  • I'm lookimg for something like this, only shouldn't 224 hex be 548 decimal?
    – David Bulko
    Nov 10 at 21:55










  • @DavidBulko yes, 0x224 = 548
    – caco3
    Nov 10 at 22:00















up vote
1
down vote













Shift and sum them (as it done in DataInputStream#readInt())



byte bytes = {0, 0, 0x2, 0x24};
int i = ((bytes[0] << 24) + (bytes[1]<< 16) + (bytes[2]<< 8) + (bytes[3] << 0));
System.out.println(i);


Output:



548



Maybe you're looking for DataInputStream?



byte bytes = {0, 0, 0x2, 0x24};
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(bytes));
System.out.println(inputStream.readInt());


Output:



548






share|improve this answer























  • I'm lookimg for something like this, only shouldn't 224 hex be 548 decimal?
    – David Bulko
    Nov 10 at 21:55










  • @DavidBulko yes, 0x224 = 548
    – caco3
    Nov 10 at 22:00













up vote
1
down vote










up vote
1
down vote









Shift and sum them (as it done in DataInputStream#readInt())



byte bytes = {0, 0, 0x2, 0x24};
int i = ((bytes[0] << 24) + (bytes[1]<< 16) + (bytes[2]<< 8) + (bytes[3] << 0));
System.out.println(i);


Output:



548



Maybe you're looking for DataInputStream?



byte bytes = {0, 0, 0x2, 0x24};
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(bytes));
System.out.println(inputStream.readInt());


Output:



548






share|improve this answer














Shift and sum them (as it done in DataInputStream#readInt())



byte bytes = {0, 0, 0x2, 0x24};
int i = ((bytes[0] << 24) + (bytes[1]<< 16) + (bytes[2]<< 8) + (bytes[3] << 0));
System.out.println(i);


Output:



548



Maybe you're looking for DataInputStream?



byte bytes = {0, 0, 0x2, 0x24};
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(bytes));
System.out.println(inputStream.readInt());


Output:



548







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 10 at 21:47

























answered Nov 10 at 21:41









caco3

7211415




7211415












  • I'm lookimg for something like this, only shouldn't 224 hex be 548 decimal?
    – David Bulko
    Nov 10 at 21:55










  • @DavidBulko yes, 0x224 = 548
    – caco3
    Nov 10 at 22:00


















  • I'm lookimg for something like this, only shouldn't 224 hex be 548 decimal?
    – David Bulko
    Nov 10 at 21:55










  • @DavidBulko yes, 0x224 = 548
    – caco3
    Nov 10 at 22:00
















I'm lookimg for something like this, only shouldn't 224 hex be 548 decimal?
– David Bulko
Nov 10 at 21:55




I'm lookimg for something like this, only shouldn't 224 hex be 548 decimal?
– David Bulko
Nov 10 at 21:55












@DavidBulko yes, 0x224 = 548
– caco3
Nov 10 at 22:00




@DavidBulko yes, 0x224 = 548
– caco3
Nov 10 at 22:00



Popular posts from this blog

List item for chat from Array inside array React Native

Thiostrepton

Caerphilly