This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes byte[] to int Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "byte[] to int" Watch "byte[] to int" New topic
Author

byte[] to int

Sandeep Sirsekar
Greenhorn

Joined: Apr 09, 2008
Posts: 16
How can i convert byte[] array to int can anyone please help me.
Thirugnanam Saravanan
Ranch Hand

Joined: Dec 13, 2007
Posts: 81
I think you can convert byte[] to int[] and not to int directly.

Refer the following code and let me know if I understood your requirement clearly.



Saravanan
SCJP 5.0(98%), SCWCD 5.0 (100%), OCA
Sandeep Sirsekar
Greenhorn

Joined: Apr 09, 2008
Posts: 16
ya that's perfectly fine you are upcasting byte data-type to int data-type.
but what my need is

someMethod(byteArray);//this method is provided by sun in some interface so i can't change.

i want to convert these bytes to string(that i know) but to convert it to int data-type is not known to me.
so that is the problem
Manuel Leiria
Ranch Hand

Joined: Jul 13, 2007
Posts: 171


does it work?


Manuel Leiria<br /> <br />--------------<br />Peace cannot be kept by force; it can only be achieved by understanding. <br /> Albert Einstein
Hari Srinivas
Ranch Hand

Joined: Mar 26, 2008
Posts: 46
Originally posted by Sandeep Sirsekar:
ya that's perfectly fine you are upcasting byte data-type to int data-type.
but what my need is

someMethod(byteArray);//this method is provided by sun in some interface so i can't change.

i want to convert these bytes to string(that i know) but to convert it to int data-type is not known to me.
so that is the problem


If you have a method that can convert a byte array to a String, convert it to a String and then convert the String to an integer.

int converted = Integer.parseInt(convertedString);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: byte[] to int
 
Similar Threads
Will this be seen??
Question about byte
doubt in implict casting
Can we return Byte for a method that has a return type int
About the data type