This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Converting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Converting" Watch "Converting" New topic
Author

Converting

Chiranjeevi Kanthraj
Ranch Hand

Joined: Feb 18, 2008
Posts: 289

i have an array of bytes like

i want a long value how can i convert that
i used
its giving Wrong answer
please help me


-Chiru
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14278
    
  21

It depends on how exactly the values need to be converted to a long. I suppose the idea in the code that you show is correct: the first value in the array is the most significant byte, and the last value is the least significant byte.

You have to make sure that the shift operations are being done on long values; right now, they are done on int values. You could make the 0xFF a long literal by appending "L", for example:

[ May 11, 2008: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Chiranjeevi Kanthraj
Ranch Hand

Joined: Feb 18, 2008
Posts: 289

Thank you

and That data is a Double Word data (64bit)
i want to convert that hex value to integer base 10
can you help me
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14278
    
  21

Originally posted by Pavithra Papi:
i want to convert that hex value to integer base 10

What do you mean? 0xFFL in decimal is 255L.
Chiranjeevi Kanthraj
Ranch Hand

Joined: Feb 18, 2008
Posts: 289

My problem is i have a register 0f size 32bit
and it giveing 8 digit HEX value
and i want to convert that HEX to Integer base 10 and also i have to take care of -ve values also;
[ May 12, 2008: Message edited by: Pavithra Papi ]
Chiranjeevi Kanthraj
Ranch Hand

Joined: Feb 18, 2008
Posts: 289

HI i solved that like
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Converting