What does this script do?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wow

    #1

    What does this script do?

    var abc=64; document.write( abc^2);
    then it display 66

    var abc=66; document.write( abc^2);
    then it displays 64

    What is the ^2 ? 66^2=4365
    not 64. even I mod 128 or 256, I got 4, not 64


  • Andy

    #2
    Re: What does this script do?

    > What is the ^2 ?

    ^ is raise to the power of.

    64^2 is the same as 64*64 which = 4365

    2^8 = 256 (2*2*2*2*2*2*2* 2)

    Comment

    • Andrew Thompson

      #3
      Re: What does this script do?

      On Sun, 25 Jul 2004 08:11:22 GMT, Andy wrote:
      [color=blue][color=green]
      >> What is the ^2 ? 66^2=4365[/color][/color]

      No.. 4356
      [color=blue]
      > ^ is raise to the power of.
      >
      > 64^2 is the same as 64*64 which = 4365[/color]

      and ..4096

      --
      Andrew Thompson
      http://www.PhySci.org/ Open-source software suite
      http://www.PhySci.org/codes/ Web & IT Help
      http://www.1point1C.org/ Science & Technology

      Comment

      • Andy

        #4
        Re: What does this script do?

        "Andrew Thompson" wrote[color=blue]
        > No.. 4356[/color]
        and[color=blue]
        > and ..4096[/color]

        Why the hell did I type the wrong answers in? It is plainly 4356 and 4096
        so why on earth did I type 4365 twice?

        Going mad.

        Comment

        • Lasse Reichstein Nielsen

          #5
          Re: What does this script do?

          "Wow" <a@alexa.com> writes:
          [color=blue]
          > var abc=64; document.write( abc^2);
          > then it display 66
          >
          > var abc=66; document.write( abc^2);
          > then it displays 64
          >
          > What is the ^2 ?[/color]

          Read some Javascript manual. E.g.:
          <URL:http://devedge.netscap e.com/library/manuals/2000/javascript/1.3/reference/ops.html>

          The "^" operator is the bitwise exclusive or operator. So, writing
          62 and 2 as binary,
          01000000 = 64
          ^ 00000010 = 2
          --------
          = 01000010 = 66
          [color=blue]
          > 66^2=4365[/color]

          That would be an exponetiation operator. There isn't one in Javascript,
          you must use Math.pow(66,2) for that.

          /L
          --
          Lasse Reichstein Nielsen - lrn@hotpop.com
          DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
          'Faith without judgement merely degrades the spirit divine.'

          Comment

          • Andrew Thompson

            #6
            Re: What does this script do?

            On Sun, 25 Jul 2004 09:50:46 GMT, Andy wrote:[color=blue]
            > Going mad.[/color]

            (chuckles) Notwithstanding of course, L.R.N.s
            comment they were bitwise operators ..oops!

            I was wondering vaguely whether the OP
            was refering to an exponent or 'some
            ...bit operation' in that expression, but
            noted the square of an even number should
            be even.., then when you requoted the same
            number as the square of 64, I jumped in and
            the rest, as they say, is history.

            Wait 24hrs, read back on it, and be amused. ;-)

            --
            Andrew Thompson
            http://www.PhySci.org/ Open-source software suite
            http://www.PhySci.org/codes/ Web & IT Help
            http://www.1point1C.org/ Science & Technology

            Comment

            • Wow

              #7
              Re: What does this script do?

              > > var abc=64; document.write( abc^2);[color=blue][color=green]
              > > then it display 66
              > >
              > > var abc=66; document.write( abc^2);
              > > then it displays 64
              > >
              > > What is the ^2 ?[/color]
              >
              > Read some Javascript manual. E.g.:
              >[/color]
              <URL:http://devedge.netscape.com/library/...pt/1.3/referen
              ce/ops.html>[color=blue]
              >
              > The "^" operator is the bitwise exclusive or operator. So, writing
              > 62 and 2 as binary,
              > 01000000 = 64
              > ^ 00000010 = 2
              > --------
              > = 01000010 = 66
              >[color=green]
              > > 66^2=4365[/color]
              >
              > That would be an exponetiation operator. There isn't one in Javascript,
              > you must use Math.pow(66,2) for that.
              >[/color]

              YOU ARE THE MAN!!!!


              Comment

              Working...