Array sorting by using the Bit Reverse Order ...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ravi4raj
    New Member
    • Jun 2008
    • 2

    Array sorting by using the Bit Reverse Order ...

    Hi all, Here i have to know is thr any way to sort the array according to thr Bit Reverse..
    for Example:

    If we take the Array size of 256,then the Sorting Should be like below.
    a[1] = a[256]
    a[2] = a[Bit reverse of 2] // bit lenght = Bits required for 256.
    .
    ;
    exapmle for Bit Reversing if for 256 9 bits are Needed to store the Value ,
    so Bit reversal of 1,
    bit rev( 0 0000 0001 ) = 1 0000 0000

    Bit Reversal of 2 , Bit rev(0 0000 0010) = 0 1000 0000

    like that , i want to Know Whether it is possible for Minimal steps or not
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by Ravi4raj
    Hi all, Here i have to know is thr any way to sort the array according to thr Bit Reverse..
    for Example:

    If we take the Array size of 256,then the Sorting Should be like below.
    a[1] = a[256]
    a[2] = a[Bit reverse of 2] // bit lenght = Bits required for 256.
    .
    ;
    exapmle for Bit Reversing if for 256 9 bits are Needed to store the Value ,
    so Bit reversal of 1,
    bit rev( 0 0000 0001 ) = 1 0000 0000

    Bit Reversal of 2 , Bit rev(0 0000 0010) = 0 1000 0000

    like that , i want to Know Whether it is possible for Minimal steps or not
    I'd say that if I reverse eight bits I end up with eight bits again, not nine.
    (256 different values in 0 ... 255 take up eight bits)

    kind regards,

    Jos

    Comment

    • Ravi4raj
      New Member
      • Jun 2008
      • 2

      #3
      Originally posted by JosAH
      I'd say that if I reverse eight bits I end up with eight bits again, not nine.
      (256 different values in 0 ... 255 take up eight bits)

      kind regards,

      Jos

      Thanks Jos, For ur Concern, I'm Just saying an Example.. that this will take like this ...

      ok as per ur Idea is thr any chance to do that Bit reversing of 256 array with Minimal Steps?'

      Regards,
      Raj

      Comment

      • oler1s
        Recognized Expert Contributor
        • Aug 2007
        • 671

        #4
        Raj, what exactly is your question? Sure, there is some logic to what you want. Some algorithm will be more efficient than another. I don't really see what you are asking though.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by Ravi4raj
          Thanks Jos, For ur Concern, I'm Just saying an Example.. that this will take like this ...

          ok as per ur Idea is thr any chance to do that Bit reversing of 256 array with Minimal Steps?'

          Regards,
          Raj
          Sure, suppose the function rev(i) returns the bits of parameter i reversed; all
          you have to do is:

          [code=c]
          for (i= 0; i < 256; i++) {
          int j= rev(i);
          if (j > i) /* not yet already swapped? */
          swap(array, i, j);
          }
          [/code]

          kind regards,

          Jos

          Comment

          Working...