reverse the bits in an interger?

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

    #31
    Re: reverse the bits in an interger?

    "Richard Heathfield" <rjh@see.sig.in validschrieb im Newsbeitrag
    news:NfmdnSRaOv W3O-TbnZ2dnUVZ8qydn Z2d@bt.com...
    osmium said:
    >
    >"user923005 " writes:
    >>
    >>Richard's reply was intended to be funny, and it made me laugh.
    >>
    >That's pretty darn sad. This is supposed to be a technical group to
    >help people, not a bunch of misfits trying to purposely misunderstand
    >and twist every little thing that comes along for their own purposes.
    >
    It was a joke with a purpose behind it, which I have already made plain
    Oh well, apparently I once again managed to have missed your humour ...

    Bye, Jojo


    Comment

    • Joachim Schmitz

      #32
      Re: reverse the bits in an interger?


      "Joachim Schmitz" <nospam.jojo@sc hmitz-digital.deschri eb im Newsbeitrag
      news:f5dk29$v48 $1@online.de...
      "Richard Heathfield" <rjh@see.sig.in validschrieb im Newsbeitrag
      news:NfmdnSRaOv W3O-TbnZ2dnUVZ8qydn Z2d@bt.com...
      >osmium said:
      >>
      >>"user923005 " writes:
      >>>
      >>>Richard's reply was intended to be funny, and it made me laugh.
      >>>
      >>That's pretty darn sad. This is supposed to be a technical group to
      >>help people, not a bunch of misfits trying to purposely misunderstand
      >>and twist every little thing that comes along for their own purposes.
      >>
      >It was a joke with a purpose behind it, which I have already made plain
      Oh well, apparently I once again managed to have missed your humour ...
      Guess that'll teach me to never ever again take you serious 8-)

      Bye, Jojo


      Comment

      • Richard Heathfield

        #33
        Re: reverse the bits in an interger?

        Joachim Schmitz said:
        >
        "Joachim Schmitz" <nospam.jojo@sc hmitz-digital.deschri eb...
        >"Richard Heathfield" <rjh@see.sig.in validschrieb...
        >>>
        >>It was a joke with a purpose behind it, which I have already made
        >>plain
        >Oh well, apparently I once again managed to have missed your humour
        >...
        Guess that'll teach me to never ever again take you serious 8-)
        Humour can be an extraordinarily effective teaching tool. If you don't
        benefit from it yourself, take comfort in the fact that others do.

        --
        Richard Heathfield
        "Usenet is a strange place" - dmr 29/7/1999

        email: rjh at the above domain, - www.

        Comment

        • Joachim Schmitz

          #34
          Re: reverse the bits in an interger?


          "Richard Heathfield" <rjh@see.sig.in validschrieb im Newsbeitrag
          news:4PadnVxqco bN_-fbRVnyuQA@bt.co m...
          Joachim Schmitz said:
          >
          >>
          >"Joachim Schmitz" <nospam.jojo@sc hmitz-digital.deschri eb...
          >>"Richard Heathfield" <rjh@see.sig.in validschrieb...
          >>>>
          >>>It was a joke with a purpose behind it, which I have already made
          >>>plain
          >>Oh well, apparently I once again managed to have missed your humour
          >>...
          >Guess that'll teach me to never ever again take you serious 8-)
          >
          Humour can be an extraordinarily effective teaching tool.
          Agreed. If it is recognizable as such.

          Bye, Jojo


          Comment

          • Christopher Benson-Manica

            #35
            Re: reverse the bits in an interger?

            user923005 <dcorbit@connx. comwrote:
            /* The assumption is that there are 32 usable bits */
            assert(UINT_MAX == 4294967295);
            One, presumably that constant would be better expressed using bit
            shift operators (being careful to navigate the default integer
            promotions appropriately). Two, does the code you posted handle the
            case where sizeof int is 2 and CHAR_BIT is 16 as well as the obvious
            case?

            --
            C. Benson Manica | I *should* know what I'm talking about - if I
            cbmanica(at)gma il.com | don't, I need to know. Flames welcome.

            Comment

            • CBFalconer

              #36
              Re: reverse the bits in an interger?

              Joachim Schmitz wrote:
              "Richard Heathfield" <rjh@see.sig.in validschrieb im Newsbeitrag
              >Joachim Schmitz said:
              >>"Joachim Schmitz" <nospam.jojo@sc hmitz-digital.deschri eb...
              >>>"Richard Heathfield" <rjh@see.sig.in validschrieb...
              >>>>>
              >>>>It was a joke with a purpose behind it, which I have already
              >>>>made plain
              >>>Oh well, apparently I once again managed to have missed your
              >>>humour ...
              >>>
              >>Guess that'll teach me to never ever again take you serious 8-)
              >>
              >Humour can be an extraordinarily effective teaching tool.
              >
              Agreed. If it is recognizable as such.
              Richard has been known to misfire. An outstanding example was his
              fairly recent reply in LISPTH to an (apparent) newbie.

              --
              <http://www.cs.auckland .ac.nz/~pgut001/pubs/vista_cost.txt>
              <http://www.securityfoc us.com/columnists/423>
              <http://www.aaxnet.com/editor/edit043.html>
              cbfalconer at maineline dot net



              --
              Posted via a free Usenet account from http://www.teranews.com

              Comment

              • user923005

                #37
                Re: reverse the bits in an interger?

                On Jun 21, 8:22 am, Christopher Benson-Manica
                <a...@vinland.f reeshell.orgwro te:
                user923005 <dcor...@connx. comwrote:
                /* The assumption is that there are 32 usable bits */
                assert(UINT_MAX == 4294967295);
                >
                One, presumably that constant would be better expressed using bit
                shift operators (being careful to navigate the default integer
                promotions appropriately). Two, does the code you posted handle the
                case where sizeof int is 2 and CHAR_BIT is 16 as well as the obvious
                case?
                No, but in debug mode the assert will fire and the programmer will
                hopefully be smart enough to fix it.
                --
                C. Benson Manica | I *should* know what I'm talking about - if I
                cbmanica(at)gma il.com | don't, I need to know. Flames welcome.

                Comment

                • user923005

                  #38
                  Re: reverse the bits in an interger?

                  On Jun 21, 12:24 am, "Army1987" <please....@for .itwrote:
                  "user923005 " <dcor...@connx. comha scritto nel messaggionews:1 182367011.22771 7.213030@n60g20 00hse.googlegro ups.com...
                  >
                  >
                  >
                  On Jun 20, 2:56 am, "Joachim Schmitz" <nospam.j...@sc hmitz-digital.de>
                  wrote:
                  "Richard Heathfield" <r...@see.sig.i nvalidschrieb im Newsbeitragnews :Jb2dnbMfkOTEZe XbnZ2dnUVZ8svin Z2d@bt.com...KG said:
                  >
                  Could any one tell me how to reverse the bits in an interger?
                  >
                  int reverse_bits(in t n)
                  {
                  return ~n;
                  }
                  >
                  That's inverting (1 turn into 0 and vice versa), not reverting. I understood
                  the OP wants the laest significant bit being the most significate, the 2nd
                  least being the second most and so on.
                  >
                  Bye, Jojo
                  >
                  Actually, if the O.P. had wanted the ORDER of the bits reversed, he
                  should have asked for that.
                  Richard's reply was intended to be funny, and it made me laugh.
                  >
                  Of course, anyone with 30 seconds worth of time can do a web search
                  and find plenty of integer reversal routines.
                  But the thing that makes them interesting is understanding how they
                  work.
                  [snip]
                  /* The assumption is that there are 32 usable bits in unsigned int */
                  assert(UINT_MAX == 4294967295);
                  >
                  At runtime?
                  There is no check for release mode.
                  Wouldn't it make more sense to write
                  #if UINT_MAX != 4294967295
                  #error "This program is written for machines with 32-bit ints"
                  #endif
                  There will be no discernable effect, even in debug mode for a single
                  integer comparison. I see these two as approximately equivalent.

                  There is one superiority to the #error method -- if the code is never
                  tested in debug mode, then the assert will never fire.

                  Comment

                  • Christopher Benson-Manica

                    #39
                    Re: reverse the bits in an interger?

                    user923005 <dcorbit@connx. comwrote:
                    On Jun 21, 8:22 am, Christopher Benson-Manica
                    <a...@vinland.f reeshell.orgwro te:
                    user923005 <dcor...@connx. comwrote:
                    assert(UINT_MAX == 4294967295);
                    does the code you posted handle the
                    case where sizeof int is 2 and CHAR_BIT is 16 as well as the obvious
                    case?
                    No, but in debug mode the assert will fire and the programmer will
                    hopefully be smart enough to fix it.
                    Why would the assert fire? Is there any reason why UINT_MAX must
                    have a different value for sizeof int 2/CHAR_BIT 16 and sizeof int
                    4/CHAR_BIT 8?

                    --
                    C. Benson Manica | I *should* know what I'm talking about - if I
                    cbmanica(at)gma il.com | don't, I need to know. Flames welcome.

                    Comment

                    • Army1987

                      #40
                      Re: reverse the bits in an interger?


                      "Christophe r Benson-Manica" <ataru@vinland. freeshell.orgha scritto nel messaggio news:f5e53n$t8j $1@chessie.cirr .com...
                      user923005 <dcorbit@connx. comwrote:
                      >
                      >/* The assumption is that there are 32 usable bits */
                      > assert(UINT_MAX == 4294967295);
                      >
                      One, presumably that constant would be better expressed using bit
                      shift operators (being careful to navigate the default integer
                      promotions appropriately). Two, does the code you posted handle the
                      case where sizeof int is 2 and CHAR_BIT is 16 as well as the obvious
                      case?
                      There was an assert(UCHAR_MA X == 255); right below.


                      Comment

                      • Christopher Benson-Manica

                        #41
                        Re: reverse the bits in an interger?

                        Christopher Benson-Manica <ataru@faeroes. freeshell.orgwr ote:
                        Why would the assert fire? Is there any reason why UINT_MAX must
                        have a different value for sizeof int 2/CHAR_BIT 16 and sizeof int
                        4/CHAR_BIT 8?
                        Ah, I see that I missed the assert() that was relevant here. Never
                        mind...

                        --
                        C. Benson Manica | I *should* know what I'm talking about - if I
                        cbmanica(at)gma il.com | don't, I need to know. Flames welcome.

                        Comment

                        Working...