• 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

hexa + binary(please reply)

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q 1 which would be the result of running the foll method with an input of 67?
public int Maskoff(int n){
return n|3;
}
a. the method would return 3
b. the method would return 64
c. the method would return 67
d. the method would return 4
ans. c is correct.
how r we suppose to remember the binary form of such high nos.
is there a simple way to remember this.please reply.
Q 2 what is the result of calling the foll. method with input of 2?
public int adder(int N){
return 0x1oo + N++;
}
ans:the method will return 258
to ans this correctly u should know that 0x100(hexa)=256 decimal.
how r u suppose to remember this??please help.


 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi hema
Don't try to remember it - understand it.
This following site has pretty much got the best explanation on hexadecimal, octal and decimal notation. This will definitly make you understand:
url : http://www.rz.uni-hohenheim.de/rz/sys/basics/csc102/ch3.html
Good Luck
Andreas
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Hema,
No need to remember this!! just stick to the basics
256 is the representation of that particular number in decimal format ( where the base is 10 ) .. so the number's value is equal to --256= 2*10(2) + 5*10(1) + 6*10(0) -- i use the notation 10(2) == 10 raised to the power 2 == 10*10 = 100.
if u just remember the powers of 2 ( 1,2,4,8,16,32,64,128,256,512,1024... ) or the powers of 16( 1,16,256.... ) just like u remember the powers of 10 ( 1,10,100,1000.... ) it would all become very natural.
256 in binary representation = 1*2(8) +0*........
so its 1000 0000
( its 1*16(2) + 0*16(1) + 0*16(0)
so its 100 in hex
to take a smaller number 15 = 8 + 4 + 2 + 1
= 1*2(3) + 1*2(2) + 1*2(1) + 1*2(0)
= 1111 in binary...
hope this helps.. please note that the game is slightly diff for negative numbers.. ( 2's complement rep )
cheers,
vivek
 
hema janani
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to Andreas Nerlich & vivek rai 4 ur prompt reply.
the URL add was of great help to me.if u have URL 4 any other topics u may list the same.
I think the next Hexa & shift querry by someone,would definitely be solved by me.
Thanks again
hema
reply
    Bookmark Topic Watch Topic
  • New Topic