Karu Raj

Ranch Hand

Posts: 481

posted 12 years ago

I'm not sure I understand: 0x65 is a hexadecimal value. Did you want to convert it to decimal? Here's an example if that's what you want.

*Make visible what, without you, might perhaps never have been seen.*

- Robert Bresson

Karu Raj

Ranch Hand

Posts: 481

posted 12 years ago

Sorry

I want it to convert it to decimal.

The link you gave me is the code .

but how can i evaluate for SCJP exam

I want it to convert it to decimal.

The link you gave me is the code .

but how can i evaluate for SCJP exam

Barry Gaunt

Ranch Hand

Posts: 7729

posted 12 years ago

You know that each position in a decimal number means a power of 10. Starting from the right, moving to the left, we have the number of ones, then the number of tens, then the number of hundreds, thousands, ten-thousands, and so on. So 4242 is 2 ones plus 4 tens plus 2 hundreds and 4 thousands. That is: 2 + 40 + 200 + 4000, resulting in, yes, 4242. 10 is the base of this decimal system

Hexadecimal has base 16, and octal has base 8.

In a hexadecimal number, going from right to left, you have the number of ones, the number of sixteens, the number of two-hundred-and-fifty-sixes, the number of four-thousand-and-ninety-sixes, and so on. So 0x65 means 5 ones plus 6 sixteens, that is, 5 plus, um..., 96. That makes 101 in decimal. So 0x65 (read it as 65 in hex) is 101 in decimal.

I leave the octal conversion as an exercise. Do not forget that an int literal begining with 0 is octal.

Any modern (high-)school maths book should have a few pages on this topic.

[ September 17, 2005: Message edited by: Barry Gaunt ]

six times sixteen is nintysix not eighty

[ September 17, 2005: Message edited by: Barry Gaunt ]

[ September 17, 2005: Message edited by: Barry Gaunt ]

Hexadecimal has base 16, and octal has base 8.

In a hexadecimal number, going from right to left, you have the number of ones, the number of sixteens, the number of two-hundred-and-fifty-sixes, the number of four-thousand-and-ninety-sixes, and so on. So 0x65 means 5 ones plus 6 sixteens, that is, 5 plus, um..., 96. That makes 101 in decimal. So 0x65 (read it as 65 in hex) is 101 in decimal.

I leave the octal conversion as an exercise. Do not forget that an int literal begining with 0 is octal.

Any modern (high-)school maths book should have a few pages on this topic.

[ September 17, 2005: Message edited by: Barry Gaunt ]

six times sixteen is nintysix not eighty

[ September 17, 2005: Message edited by: Barry Gaunt ]

[ September 17, 2005: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch

Getting someone to think and try something out is much more useful than just telling them the answer.

Roy Simon

Ranch Hand

Posts: 62

posted 12 years ago

if you find dividing and multiplying by 16 tough

convert the number to binary first

each hexa digit can be represented by four binary bits

eg 6==0110,f=1111and 0=0000

once you have done this

conversion to decimal will be a piece of cake as you can conver the decimal to binary

eg 111 = 1*2^0 + 1*2^1 + 1*2^2 == 7

pls note the ^ stands for power and not XOR

Regards

Simon

convert the number to binary first

each hexa digit can be represented by four binary bits

eg 6==0110,f=1111and 0=0000

once you have done this

conversion to decimal will be a piece of cake as you can conver the decimal to binary

eg 111 = 1*2^0 + 1*2^1 + 1*2^2 == 7

pls note the ^ stands for power and not XOR

Regards

Simon

It is sorta covered in the JavaRanch Style Guide. |