• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

converting hexa value to decimal

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Am getting the data from a binay and hexa decimal text file where i am reading it as string and converting to byte array. but i am not able to convert the byte array value to decimal. if i am storing the value "D500" into byte array. once i read it it coming as -43. can any one please give me the solution

- Basavaraj
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you be specific about your code?
 
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Basav,

The hexadecimal value 0xD500 corresponds to decimal radix value 54528.

This value is very large to fit into byte.

So, my suggestion is that you should change your array from byte to int.

Hope that helps
 
basav raj
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The thing here is, in the file first two bytes will specifies the length of next data. say if 0A00 is there then we need to do flipping oparation. from
0 0
A 0
After flipping the value will be 0A whose decimal value is 11.
Below is the function i have written to find the length and to do the flipping oparation but its failing in the case of the value "5D00".
public int flipBytes(byte[] b){
int result = 0;
int b1 = new Byte(b[0]).intValue();
int b2 = new Byte(b[1]).intValue();

result = (int)b1 + (b2*256);
return result;
}
I tried all ways like int, long, short data types nothing is worked out. can you please suggest me.

Thanks
Basavaraj G
 
Ew. You guys are ugly with a capital UG. Here, maybe this tiny ad can help:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic