• 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

Question from Java Applet Test 2

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What will be the result of calling the following method with an input of 2
public int adder(int N) {
return 0x100 + N++;
}
1. It will return 258
2. It will return 102
3. It will return 259
4. It will return 103
The correct answer is 1
I really don't know how to convert hexadecimal to decimal and vice versa. Also I don't know the conversion between octal and decimal too.
I can convert the simple ones for example 0x12.
Is there any logic for this?
Please someone help me with this.
Thanx
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Punitha,
I've some notes on working with hex, octal and binary posted here http://webhome.idirect.com/~jgriscti/oper/binhex.html.
Hope they help.
------------------
Jane
The cure for boredom is curiosity.
There is no cure for curiosity.
-- Dorothy Parker
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hexadecimals are in base 16 so in bit format that is 4 bits. With that in mind, convert 0x100 to bits gives you:
 1      0      0
 |      |      |
0001 0000 0000 = 256 in decimal
Then you add N++ to it which is 2 since it is a post incrementor, so that gives you 258.
Go through the link Jane has above, it really explains these concepts well.
Bill
[This message has been edited by bill bozeman (edited December 04, 2000).]
[This message has been edited by bill bozeman (edited December 04, 2000).]
 
Punitha krishna
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx Bill. Jane thanks for the URL. I just started going through it and it makes sense to me.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic