• 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

How to evaluate the expression 14^23

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question is from http://www.javaprepare.com/quests/test.html
What is the result of evaluating the expression 14^23. Select the one correct answer.
A. 25
B. 37
C. 6
D. 31
E. 17
F. 9
G. 24
Answer: A
Please help me-- how to evaluate the expression 14^23? Great thanks!
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
^ is the XOR operator which means that the answer is 1 whenever the bits are different.
14 is 00001110
23 is 00010111
so the answer is
00011001 which is 25...
got it ?
moreover we'd like you to read the Javaranch Naming Policy and register again.
Thank you for your cooperation
[ January 24, 2002: Message edited by: Valentin Crettaz ]
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The point is: how I can convert a decimal number into binary in the exam that is limit in time?
I have certain rules:
1)
c = a & b;
c must be less or equal than to min( a, b).
For example:
That is the result of the following operation:
15 & 69
a) 56
b) 37
c) 16
d) 5
The correct answer is "d"
2) c = a | b
c must be greater or equal than max( a, b);
For example:
That is the result of the following operation:
15 | 69
a) 56
b) 37
c) 16
d) 79

The correct answer is "d"

But, what I can do with XOR?
Or with a question like this?:
That is the result of the following operation:
15 | 69
a) 80
b) 96
c) 85
d) 79
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you should still be able to convert small decimal number to binary, that really not that difficult.
You just have to decompose the decimal number in power of two.
For instance:
84 is 64+16+4 which gives 01010100 in binary because
(0*128)+(1*64)+(0*32)+(1*16)+(0*8)+(1*4)+(0*2)+(0*1) = 84.
Note that 128,64,32,16,8,4,2,1 are powers of 2. With that you can do everything...
HIH
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you should first convert decimals to binary numbers i.e., 1011 form and then do operations like &, | or ^ etc and you will get conversion again in binary form. Then convert that binary result back to decimal and you will get the answer. The conversion is very easy if you practice it a little bit.
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
further to valentin's explanation, in order to get a binary fast:
write down the following in a piece of paper:
128 64 32 16 8 4 2 1
now say you want to convert decimal 5 to binary.
in the above bit pattern, place 1 below those numbers which will together give you 5 - so place 1 below 4 and 1, fill the rest fill with 0.
128 64 32 16 8 4 2 1
0 0 0 0 0 1 0 1
that gives you the 8 bit pattern of decimal five quick and easy.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, Valentin, Ruchi and sanjay.
Your answers are helpful!!!
 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For bitwise ops, I use an old memory trick I developed when I was learning IBM 370 Assembler a million years ago:
& - 1 and 1
| - either 1
^ - only one
For the & operator, then both bits must equal one yielding 1.
For the | operator, if either bit equals 1, then the yield is 1.
For the ^ operator, only 1 bit can equal 1 to yield 1.
The other helpful tool is to use a calculator for bit ops - the MS Windows calculator has a scientific view and you can switch back and forth from decimal to binary to see bit patterns - then you can use the And, Or and Xor functions - you see each op as it is executed.
 
reply
    Bookmark Topic Watch Topic
  • New Topic