Exponent Problem
-
Notice the comments. What's wrong here?
import java.lang.*;
import java.lang.Math.*;public class Exponent
{
public static void main(String[] args)
{
int iBase = 10;
int iExponent = 2;double dCubed = Math.pow ( iBase, iExponent); // Produces 100.0 System.out.println( dCubed ); int iResult = iBase ^ iExponent; // Produces 8 System.out.println( iResult ); }
Everything makes sense in someone's mind
-
Notice the comments. What's wrong here?
import java.lang.*;
import java.lang.Math.*;public class Exponent
{
public static void main(String[] args)
{
int iBase = 10;
int iExponent = 2;double dCubed = Math.pow ( iBase, iExponent); // Produces 100.0 System.out.println( dCubed ); int iResult = iBase ^ iExponent; // Produces 8 System.out.println( iResult ); }
Everything makes sense in someone's mind
In Java, the ' ^ ' is a bitwise operator, not a power operator!
John P.
-
In Java, the ' ^ ' is a bitwise operator, not a power operator!
John P.
Which does exactly what?
Everything makes sense in someone's mind
-
Which does exactly what?
Everything makes sense in someone's mind
Gosh, all I did was go to "java.sun.com" --- all the answers are RIGHT THERE! Here! I did it for you: The bitwise ^ operator performs a bitwise exclusive OR operation. So 10 = 1010 2 = 0010 Exclusive OR = 1000 = decimal 8!
John P.
modified on Wednesday, August 20, 2008 3:58 PM
-
Gosh, all I did was go to "java.sun.com" --- all the answers are RIGHT THERE! Here! I did it for you: The bitwise ^ operator performs a bitwise exclusive OR operation. So 10 = 1010 2 = 0010 Exclusive OR = 1000 = decimal 8!
John P.
modified on Wednesday, August 20, 2008 3:58 PM
I looked it up too. I don't understand what 'bitwise' means. It it was so much trouble for you, why bother responding at all?
Everything makes sense in someone's mind
-
I looked it up too. I don't understand what 'bitwise' means. It it was so much trouble for you, why bother responding at all?
Everything makes sense in someone's mind
KMAROIS wrote:
It it was so much trouble for you, why bother responding at all?
if it's too much for you to 1) search the web, 2) read the docs, and 3) try to understand a wise answer you got, why bothering asking ? bitwise operators are operators operating directly on the bits rather than full bytes. so, as the other guy was saying, the ^ operator is the XOR (exclusive OR) bitwise operator.
10 = 1010
2 = 0010^ 1000 -> 8