Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

byte[] to int

 
Sandeep Sirsekar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i convert byte[] array to int can anyone please help me.
 
Thirugnanam Saravanan
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Sandeep Sirsekar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


does it work?
 
Hari Srinivas
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic