Pass by Reference as "essential" to swap method exposed as a lie

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

    #16
    Re: Pass by Reference as "essential " to swap method exposed as a lie

    On Oct 15, 1:22 pm, Jon Skeet [C# MVP] <sk...@pobox.co mwrote:
    >
    You didn't try it, did you? The whole point of the example is to show
    that no temporary variable is needed (for integers), and certainly
    there are no pointers involved. Hint: ^ is the XOR operator in C#.
    >
    Yeah, neat trick, I just tried it. It only works for binary systems
    of base 2.

    Lern something new everyday, Vern.

    RL

    Comment

    • =?Utf-8?B?S0g=?=

      #17
      Re: Pass by Reference as &quot;essential &quot; to swap method exposed as a l

      >It only works for binary systems of base 2.

      Who is this guy? Dude read the first sentence:


      Binary and base-2 numbering are synonomous.


      "raylopez99 " wrote:
      On Oct 15, 1:22 pm, Jon Skeet [C# MVP] <sk...@pobox.co mwrote:
      >

      You didn't try it, did you? The whole point of the example is to show
      that no temporary variable is needed (for integers), and certainly
      there are no pointers involved. Hint: ^ is the XOR operator in C#.
      >
      Yeah, neat trick, I just tried it. It only works for binary systems
      of base 2.
      >
      Lern something new everyday, Vern.
      >
      RL
      >

      Comment

      • raylopez99

        #18
        Re: Pass by Reference as &quot;essential &quot; to swap method exposed as a l

        On Oct 15, 3:30 pm, KH <K...@discussio ns.microsoft.co mwrote:
        It only works for binary systems of base 2.
        >
        Who is this guy? Dude read the first sentence:http://en.wikipedia.org/wiki/Binary_numeral_system
        >
        Binary and base-2 numbering are synonomous.
        >
        Isn't that what I said?

        Now solve this:

        boolean x;
        if ((x*!x == (!x + x))) {Console.WriteL ine ("KH is a dunce");} else
        {Console.Write( "RayLopez is a fool");} //evaluates to true

        //DeMorgan's Theorem of Boolean (binary) base-2 algebra.

        RL

        Comment

        • Family Tree Mike

          #19
          Re: Pass by Reference as &quot;essential &quot; to swap method exposed as a l

          That code does not compile, as Booleans (boolean is not defined), can not be
          multiplied or added.

          Operator '*' cannot be applied to operands of type 'bool' and 'bool'
          C:\...\Program. cs 24 9 SwapCode
          Operator '+' cannot be applied to operands of type 'bool' and 'bool'
          C:\...\Program. cs 24 9 SwapCode


          "raylopez99 " <raylopez99@yah oo.comwrote in message
          news:fda65d84-48c4-4d11-95f6-893172f48f0e@k3 7g2000hsf.googl egroups.com...
          On Oct 15, 3:30 pm, KH <K...@discussio ns.microsoft.co mwrote:
          It only works for binary systems of base 2.
          >
          Who is this guy? Dude read the first
          sentence:http://en.wikipedia.org/wiki/Binary_numeral_system
          >
          Binary and base-2 numbering are synonomous.
          >
          Isn't that what I said?

          Now solve this:

          boolean x;
          if ((x*!x == (!x + x))) {Console.WriteL ine ("KH is a dunce");} else
          {Console.Write( "RayLopez is a fool");} //evaluates to true

          //DeMorgan's Theorem of Boolean (binary) base-2 algebra.

          RL

          Comment

          • raylopez99

            #20
            Re: Pass by Reference as &quot;essential &quot; to swap method exposed as a l

            Well then I am the greater fool it seems.

            Perhaps a BitArray is called for, then defining a class that can have
            members who can be added and subtracted and multiplied according to
            boolean algebra, which perhaps might require a class defining the laws
            of boolean algebra. Harder than I thought.

            Also my initial formula for deMorgan's law is off a bit I believe.

            RL

            Family Tree Mike wrote:
            That code does not compile, as Booleans (boolean is not defined), can not be
            multiplied or added.
            >
            Operator '*' cannot be applied to operands of type 'bool' and 'bool'
            C:\...\Program. cs 24 9 SwapCode

            Comment

            • Ben Voigt [C++ MVP]

              #21
              Re: Pass by Reference as &quot;essential &quot; to swap method exposed as a l

              Family Tree Mike wrote:
              That code does not compile, as Booleans (boolean is not defined), can
              not be multiplied or added.
              >
              Operator '*' cannot be applied to operands of type 'bool' and 'bool'
              C:\...\Program. cs 24 9 SwapCode
              Operator '+' cannot be applied to operands of type 'bool' and 'bool'
              C:\...\Program. cs 24 9 SwapCode
              * and + are "and" and "or" operations in conventional notation. C, C++, C#,
              Java all use "&" and "|" for this.

              Note the remaining problem with the uninitialized variable.

              But he did indeed get DeMorgan's theorem wrong, it is:

              /(A + B) = (/A) * (/B)

              or in C# style

              !(A | B) == (!A) & (!B)

              The identity holds for all combinations of boolean A and B
              >
              >
              "raylopez99 " <raylopez99@yah oo.comwrote in message
              news:fda65d84-48c4-4d11-95f6-893172f48f0e@k3 7g2000hsf.googl egroups.com...
              On Oct 15, 3:30 pm, KH <K...@discussio ns.microsoft.co mwrote:
              >>>It only works for binary systems of base 2.
              >>
              >Who is this guy? Dude read the first
              >sentence:http://en.wikipedia.org/wiki/Binary_numeral_system
              >>
              >Binary and base-2 numbering are synonomous.
              >>
              >
              Isn't that what I said?
              >
              Now solve this:
              >
              boolean x;
              if ((x*!x == (!x + x))) {Console.WriteL ine ("KH is a dunce");} else
              {Console.Write( "RayLopez is a fool");} //evaluates to true
              >
              //DeMorgan's Theorem of Boolean (binary) base-2 algebra.
              >
              RL

              Comment

              • =?Utf-8?B?S0g=?=

                #22
                Re: Pass by Reference as &quot;essential &quot; to swap method exposed as a l

                Isn't that what I said?

                No, you said "binary systems of base 2", implying that binary numbering
                could use some other base number.


                "raylopez99 " wrote:
                On Oct 15, 3:30 pm, KH <K...@discussio ns.microsoft.co mwrote:
                >It only works for binary systems of base 2.
                Who is this guy? Dude read the first sentence:http://en.wikipedia.org/wiki/Binary_numeral_system

                Binary and base-2 numbering are synonomous.
                >
                Isn't that what I said?
                >
                Now solve this:
                >
                boolean x;
                if ((x*!x == (!x + x))) {Console.WriteL ine ("KH is a dunce");} else
                {Console.Write( "RayLopez is a fool");} //evaluates to true
                >
                //DeMorgan's Theorem of Boolean (binary) base-2 algebra.
                >
                RL
                >

                Comment

                Working...