# Converting Hexdecimal numbers....

Narasimha Rao B.

Ranch Hand

Posts: 205

posted 12 years ago

- 0

Hi,

1) Can, any of you explain how to convert big Hex decimal numbers to decimal. For ex, how will you convert 0xffffffc9 to decimal number.

2)

byte b = 0; int i=0;

Is there any short cut method is there to solve the below expression,

b = (byte)(b + (b - (i = 0xffffffc9)))

Thanks in Advance....

1) Can, any of you explain how to convert big Hex decimal numbers to decimal. For ex, how will you convert 0xffffffc9 to decimal number.

2)

byte b = 0; int i=0;

Is there any short cut method is there to solve the below expression,

b = (byte)(b + (b - (i = 0xffffffc9)))

Thanks in Advance....

Narasimha

Ryan Wilson

Ranch Hand

Posts: 65

posted 12 years ago

- 0

byte b = 0; int i=0;

b = (byte)(b + (b - (i = 0xffffffc9)))

0xffffffc9 is going to be negative because the leftmost bit is 1. (f = 1111)

so the number is going to be 111........11001001

because c = 1100 and 9 = 1001.

Flip the bits and add 1.

000...........00110110 + 1 = 000....00110111 = -55

b = (byte)(b + (b - (-55)))

b = (byte)(b + 55)

b = (byte)(0 + 55)

b = 55

I hope this helps

b = (byte)(b + (b - (i = 0xffffffc9)))

0xffffffc9 is going to be negative because the leftmost bit is 1. (f = 1111)

so the number is going to be 111........11001001

because c = 1100 and 9 = 1001.

Flip the bits and add 1.

000...........00110110 + 1 = 000....00110111 = -55

b = (byte)(b + (b - (-55)))

b = (byte)(b + 55)

b = (byte)(0 + 55)

b = 55

I hope this helps

Bert Bates

author

Sheriff

Sheriff

Posts: 8898

5

posted 12 years ago

- 0

Narasimha -

First here's a link that might help...

http://www.coderanch.com/t/241326/java-programmer-SCJP/certification/Converting-Hexadecimal-literals

The key points are:

1 - For anyone new to JavaRanch - the exam won't ask you to convert big hex or octal or binary numbers!

2 - The exam WILL ask you to understand how two's complement numbers are stored, and how the >>, >>>, << operators affect these two's complement numbers.

- Bert

UnderSecretary to the Minister of Keep your Focus

First here's a link that might help...

http://www.coderanch.com/t/241326/java-programmer-SCJP/certification/Converting-Hexadecimal-literals

The key points are:

1 - For anyone new to JavaRanch - the exam won't ask you to convert big hex or octal or binary numbers!

2 - The exam WILL ask you to understand how two's complement numbers are stored, and how the >>, >>>, << operators affect these two's complement numbers.

- Bert

UnderSecretary to the Minister of Keep your Focus

Spot false dilemmas now, ask me how!

(If you're not on the edge, you're taking up too much room.)

posted 12 years ago

- 0

if you need some more info -- check out our handy dandy search feature. I did a search for "convert hexadecimal" and got a lot of good hits.

Enjoy!

Enjoy!

- Jess

Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep

I agree. Here's the link: http://aspose.com/file-tools |