# \[?\] Rearrange the following binary data?

**URL:** <https://community.wolfram.com/t/rearrange-the-following-binary-data/12386>\
**Category:** Questions\
**Tags:** data-science, algebra, logic\
**Created:** [April 26, 2018, 12:28pm UTC](https://community.wolfram.com/t/rearrange-the-following-binary-data/12386 "2018-04-26T12:28:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![christospapahristodoulou](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/christospapahristodoulou/32/20809_2.png) [@christospapahristodoulou](https://community.wolfram.com/u/christospapahristodoulou)\
**Post date:** [April 26, 2018, 12:28pm UTC](https://community.wolfram.com/t/rearrange-the-following-binary-data/12386/1 "2018-04-26T12:28:19Z")

</div>

The data is given by:

```
q = Flatten[
  Table[{a, b, c, d}, {a, 0, 1}, {b, 0, 1}, {c, 0, 1}, {d, 0, 1}], 3].
Mathematica gives the following order:
{{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 1, 0}, {0, 0, 1, 1}, {0, 1, 0, 
  0}, {0, 1, 0, 1}, {0, 1, 1, 0}, {0, 1, 1, 1}, {1, 0, 0, 0}, {1, 0, 
  0, 1}, {1, 0, 1, 0}, {1, 0, 1, 1}, {1, 1, 0, 0}, {1, 1, 0, 1}, {1, 
  1, 1, 0}, {1, 1, 1, 1}};

```

I would like the data to be ordered as below (i.e. the order should be, 2nd, 4th, 6th,8th, 10th, etc):

```
newdata4 = {{0, 0, 0, 1}, {0, 0, 1, 1}, {0, 1, 0, 1}, {0, 1, 1, 
    1}, {1, 0, 0, 1}, {1, 0, 1, 1}, {1, 1, 0, 1}, {1, 1, 1, 1}, {0, 0,
     0, 0}, {0, 0, 1, 0}, {0, 1, 0, 0}, {0, 1, 1, 0}, {1, 0, 0, 
    0}, {1, 0, 1, 0}, {1, 1, 0, 0}, {1, 1, 1, 0}};

```

Can anyone help me? Im fact I would like to use a much larger combination of binaries and the documentation does not help!

---

<div class="post-metadata">

**Author:** ![danl](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/danl/32/41267_2.png) [@danl](https://community.wolfram.com/u/danl)\
**Post date:** [April 26, 2018, 1:36pm UTC](https://community.wolfram.com/t/rearrange-the-following-binary-data/12386/2 "2018-04-26T13:36:32Z")

</div>

Could join evens to odds, as below.

```
qEvenOdd = Join[q[[2 ;; -1 ;; 2]], q[[1 ;; -2 ;; 2]]]

(* {{0, 0, 0, 1}, {0, 0, 1, 1}, {0, 1, 0, 1}, {0, 1, 1, 1}, {1, 0, 0, 
  1}, {1, 0, 1, 1}, {1, 1, 0, 1}, {1, 1, 1, 1}, {0, 0, 0, 0}, {0, 0, 
  1, 0}, {0, 1, 0, 0}, {0, 1, 1, 0}, {1, 0, 0, 0}, {1, 0, 1, 0}, {1, 
  1, 0, 0}, {1, 1, 1, 0}} *)

```

---

<div class="post-metadata">

**Author:** ![christospapahristodoulou](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/christospapahristodoulou/32/20809_2.png) [@christospapahristodoulou](https://community.wolfram.com/u/christospapahristodoulou)\
**Post date:** [April 26, 2018, 1:42pm UTC](https://community.wolfram.com/t/rearrange-the-following-binary-data/12386/3 "2018-04-26T13:42:43Z")

</div>

Thanks very much Daniel!!! I read very often your posts and comments and appreciate it.

---

<div class="post-metadata">

**Author:** ![henrikschachner](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/henrikschachner/32/32119_2.png) [@henrikschachner](https://community.wolfram.com/u/henrikschachner)\
**Post date:** [April 26, 2018, 6:35pm UTC](https://community.wolfram.com/t/rearrange-the-following-binary-data/12386/4 "2018-04-26T18:35:52Z")

</div>

Is it this what you really want? :

```
IntegerDigits[#, 2, 4] & /@ SortBy[Range[0, 15], EvenQ]

```

Or you can generalize:

```
oddEvenDigits[max_Integer] := IntegerDigits[#, 2, Ceiling[Log[max]/Log[2.]]] & /@ SortBy[Range[0, max], EvenQ]

```

---

<div class="post-metadata">

**Author:** ![christospapahristodoulou](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/christospapahristodoulou/32/20809_2.png) [@christospapahristodoulou](https://community.wolfram.com/u/christospapahristodoulou)\
**Post date:** [April 26, 2018, 7:27pm UTC](https://community.wolfram.com/t/rearrange-the-following-binary-data/12386/5 "2018-04-26T19:27:47Z")

</div>

Excellent Henrik!  
But I think the last part is:  
IntegerDigits[#, 2, Ceiling[Log[max]/Log[2.]]] & /@  
SortBy[Range[0, max - 1], EvenQ];  
otherwise it adds one more with zeros.

---

<div class="post-metadata">

**Author:** ![henrikschachner](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/henrikschachner/32/32119_2.png) [@henrikschachner](https://community.wolfram.com/u/henrikschachner)\
**Post date:** [April 26, 2018, 7:50pm UTC](https://community.wolfram.com/t/rearrange-the-following-binary-data/12386/6 "2018-04-26T19:50:54Z")

</div>

oddEvenDigits[15]  
(\* Out: {{0,0,0,1},{0,0,1,1},{0,1,0,1},{0,1,1,1},{1,0,0,1},{1,0,1,1},{1,1,0,1}  
,{1,1,1,1},{0,0,0,0},{0,0,1,0},{0,1,0,0},{0,1,1,0},{1,0,0,0},{1,0,1,0}  
,{1,1,0,0},{1,1,1,0}} \*)

… I did not regard `max` (i.e. the argument of my `oddEvenDigits`) as a power of 2. It can be just any number.

For the case of “all combination” write

```
oddEvenDigits[2^n - 1]

```

---

<div class="post-metadata">

**Author:** ![christospapahristodoulou](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/christospapahristodoulou/32/20809_2.png) [@christospapahristodoulou](https://community.wolfram.com/u/christospapahristodoulou)\
**Post date:** [April 27, 2018, 6:17am UTC](https://community.wolfram.com/t/rearrange-the-following-binary-data/12386/7 "2018-04-27T06:17:16Z")

</div>

Thanks very much Henrik! I appreciate your time.  
This is exactly what I did when I regarded your formulation as (max - 1), because you get for instance oddEvenDigits[31] if n = 5.
