Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Exponent Problem

Exponent Problem

Scheduled Pinned Locked Moved Java
javahelpquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kevin Marois
    wrote on last edited by
    #1

    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

    R 1 Reply Last reply
    0
    • K Kevin Marois

      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

      R Offline
      R Offline
      Reagan Conservative
      wrote on last edited by
      #2

      In Java, the ' ^ ' is a bitwise operator, not a power operator!

      John P.

      K 1 Reply Last reply
      0
      • R Reagan Conservative

        In Java, the ' ^ ' is a bitwise operator, not a power operator!

        John P.

        K Offline
        K Offline
        Kevin Marois
        wrote on last edited by
        #3

        Which does exactly what?

        Everything makes sense in someone's mind

        R 1 Reply Last reply
        0
        • K Kevin Marois

          Which does exactly what?

          Everything makes sense in someone's mind

          R Offline
          R Offline
          Reagan Conservative
          wrote on last edited by
          #4

          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

          K 1 Reply Last reply
          0
          • R Reagan Conservative

            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

            K Offline
            K Offline
            Kevin Marois
            wrote on last edited by
            #5

            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

            S 1 Reply Last reply
            0
            • K Kevin Marois

              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

              S Offline
              S Offline
              super_ttd
              wrote on last edited by
              #6

              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


              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups