Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

byte[] to int  RSS feed

 
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.
 
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
 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


does it work?
 
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);
 
I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!