[Question]
  [
This is my first challenge on ppcg!
### Input
A string consisting of two different ascii characters. For example
```
ABAABBAAAAAABBAAABAABBAABA
```
### Challenge
The task is to decode this string following these rules:
1. Skip the first two characters
2. Split the rest of the string into groups of 8 characters
3. In each group, replace each character with `0` if that character is the same as the first character of the original string, and with `1` otherwise
4. Now each group represents a byte. Convert each group to character from byte char code
5. Concatenate all characters
### Example
Let's decode the above string.
```
 AB  AABBAAAA  AABBAAAB  AABBAABA
 ^^     ^         ^         ^
 |      |         |         |
 |      \---------|---------/
 |                |
Skip      Convert to binary
```
Notice that `A` is the first character in the original string and `B` is the second. Therefore, replace each `A` with `0` and each `B` with `1`. Now we obtain:
```
00110000  00110001  00110010
```
which is `[0x30, 0x31, 0x32]` in binary. These values represent characters `["0", "1", "2"]` respectively, so the final output should be `012`.
### Scoring
This is, of course, [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), which means make your code as short as possible. Score is measured in bytes.
### Constraints and IO format
Standard rules apply. Here are some additional rules:
* You can assume valid input
	+ Input string consists of exactly two different characters
	+ The first two characters are different
	+ The minimal length of the input string is 2 characters
	+ The length will always give 2 modulo 8
* You can assume the string will always consist only of printable ASCII characters
	+ Both in the input and in the decoded string
* Leading and trailing whitespace are allowed in the output (everything that matches `/\s*/`)
  
[Answer]
# [brainfuck](https://github.com/TryItOnline/brainfuck), ~~76 71~~ 65 bytes
-6 bytes thanks to Nitrodon!
```
,>>,,[>>++++++++[-[->+<]<<<<[->+>-<<]>>[[-]>>+<<]>[->++<],>>]<.<]
```
[Try it online!](https://tio.run/##NYtRCoBACEQPtGsnkAG9hvhRQRALfQSd3zS2B@rMMG73el7Hs4@IDvRuQJsYGaGxc1IKxOyAGeVupSvNQj46L@wRoiKaU3x3ev29vA "brainfuck – Try It Online")
Feels weird beating Python...
[Answer]
# [Stax](https://github.com/tomtheisen/stax), ~~15~~ 11 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
ó║¥U⌂½íèäöñ
```
[Run and debug it at staxlang.xyz!](https://staxlang.xyz/#p=a2ba9d557faba18a8494a4&i=ABAABBAAAAAABBAAABAABBAABA%0A%0A+%09+%09+%09++%09%09+%09%09+++%09%09+%09%09%09++%09++%09%09+%09%09%09%09+%09%09+%09%09%09%09+%09%09+++%09++%09%09+%09%09+++%09%09++%09+%09&a=1&m=1)
~~Quick 'n' dirty approach. Working on improving it.~~ Improved it!
### Unpacked (13 bytes) and explanation
```
2:/8/{{[Im:bm
2:/              Split at index 2. Push head, then tail.
   8/            Split into length-8 segments.
     {      m    Map block over each segment:
      {  m         Map block over each character:
       [             Copy first two elements (below) in-place.
        I            Index of character in first two characters.
          :b       Convert from binary.
                 Implicit print as string.
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 10 bytes
```
¦¦Sk8ôJCçJ
```
[Try it online!](https://tio.run/##MzBNTDJM/f//0LJDy4KzLQ5v8XI@vNzr/39HJ0dHJyAGATAN5Ts5AgA "05AB1E – Try It Online")
-3 thanks to emigna.
---
```
Ù             # Unique letters, in order they appear.
 v            # For each...
  yN:         # Push letter and index, replace in input.
     }        # End loop.
      ¦¦      # Remove first x2.
        8ô    # Split into eighths.
          C   # Convert to integer.
           ç  # Convert to char.
            J # Join together entire result.
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 67 bytes
```
s=>s.replace(/./g,x=(c,i)=>(x=x*2|c==s[1],Buffer(i<3|i&7^1?0:[x])))
```
[Try it online!](https://tio.run/##XU3LCsIwELz7GT1IIrW1ehAkG0l@o1QoMSmR0pRGJYf@e0za4mtfM8vMsrf6WVsx6P6@7cxVegXeArXZIPu2FhLlWd6kDpBINQaKHLjNfhQAtiyqlD@UkgPS5DDq9fFSnHen0lUYYy9MZ00rs9Y0SKGEccZ46BgTLjtnCcarPzOhIWOFMREaMdJfXMTZSMgMk/DWF8/3Hfn4aXjuXw "JavaScript (Node.js) – Try It Online")
### How?
We use two different syntaxes of the `Buffer` constructor:
* [**`Buffer([n])`**](https://nodejs.org/docs/latest-v4.x/api/buffer.html#buffer_new_buffer_array) generates a buffer containing the sole byte **n** and is coerced to the corresponding ASCII character. Only the 8 least significant bits of **n** are considered.
* [**`Buffer(n)`**](https://nodejs.org/docs/latest-v4.x/api/buffer.html#buffer_new_buffer_size) generates a buffer of **n** bytes. Therefore, `Buffer(0)` generates an empty buffer, which is coerced to an empty string.
*Note: They both are deprecated in recent Node versions. `Buffer.from([n])` and `Buffer.alloc(n)` should be used instead.*
### Commented
```
s =>                   // given the input string s
  s.replace(/./g, x =  // initialize x to a non-numeric value (will be coerced to 0)
    (c, i) => (        // for each character c at position i in s:
      x = x * 2 |      //   shift x to the left
          c == s[1],   //   and append the new bit, based on the comparison of c with s[1]
      Buffer(          //   invoke the constructor of Buffer (see above):
        i < 3 |        //     if i is less than 3
        i & 7 ^ 1 ?    //     or i is not congruent to 1 modulo 8:
          0            //       replace c with an empty string
        :              //     else:
          [x]          //       replace c with the ASCII char. whose code is the LSB of x
      )                //   end of Buffer constructor
  ))                   // end of replace(); return the new string
```
[Answer]
## bash, ~~59~~ ~~58~~ 52 bytes
```
tr -t "$1" 01 <<<$1|cut -c3-|fold -8|sed 'i2i
aP'|dc
```
[Try it online!](https://tio.run/##S0oszvj/v6RIQbdEQUnFUEnBwFDBxsZGxbAmubREQTfZWLcmLT8nRUHXoqY4NUVBPdMokysxQL0mJfn///8KFQoKFUAMAmAayq9QAAA)
Thanks to [Cows quack](https://codegolf.stackexchange.com/users/41805/cows-quack) for saving 6 bytes.
This challenge works remarkably well with a series of coreutils (and `dc` to do the conversion and output at the end). First, we use
```
tr -t "$1" 01 <<<$1
```
to transliterate the two characters in the input to zeroes and ones. The `-t` flag truncates the first argument to the length of the second, so this reduces to transliterating the first two characters in the input to `0` and `1`, which is what we want. Then,
```
cut -c3-
```
removes the first two characters, and
```
fold -8
```
outputs 8 of the characters per line. Finally, the `sed` command turns each line into a `dc` snippet that reads the number as binary and outputs that byte.
[Answer]
# Z80 machine code on an Amstrad CPC, ~~32 31~~ 30 bytes
```
000001  0000  (9000)        ORG &9000
000002  9000  EB            EX DE, HL
000003  9001  46            LD B, (HL)
000004  9002  23            INC HL
000005  9003  5E            LD E, (HL)
000006  9004  23            INC HL
000007  9005  56            LD D, (HL)
000009  9006  1A            LD A, (DE)
000010  9007  05            DEC B
000011  9008  13            INC DE
000012  9009  4F            LD C, A
000014  900A                Light
000015  900A  26 01         LD H, &01
000016  900C                Last
000017  900C  13            INC DE
000018  900D  05            DEC B
000019  900E  C8            RET Z
000021  900F                Loop
000022  900F  1A            LD A, (DE)
000023  9010  B9            CP C
000024  9011  28 01         JR Z, Lable
000025  9013  37            SCF
000026  9014                Lable
000027  9014  ED 6A         ADC HL, HL
000028  9016  30 F4         JR NC, Last
000029  9018  7D            LD A, L
000030  9019  CD 5A BB      CALL &BB5A
000032  901C  18 EC         JR Light
```
The code takes the instruction *replace each character with `0` if that character is the same as the first character of the original string, and with `1` otherwise* literally and doesn't ever bother to check that a character matches the second character in the input string. It just checks for same-as-first-character and different-from-first-character.
I ran out of registers (the Z80 only has 7 easily usable 8-bit registers, the rest need longer instructions) so I put `&01` in `H`, along with using `L` to build up the ASCII character (I just realised it's unnecessary to initialise `L`, saving one byte). When `H` overflows into the Carry flag, the character in `L` is ready to be output. Luckily, there is a 16-bit `ADC` (**Ad**d with **C**arry) that does the job of a left-shift instruction.
`(DE)` can only be read into `A` although `(HL)` can be read into any 8-bit register, so it was a compromise which one to use. I couldn't compare `(DE)` with `C` directly, so I had to load one into `A` first. The labels are just random words that start with `L` (a requirement of the assembler).
* `A` the Accumulator - the only register that can do comparisons
* `B` the counter register ~~for the instruction `DJNZ`: **D**ecrement (`B`) and **J**ump if **N**on **Z**ero~~. By rearranging the code, I was able to do the job of `DJNZ` with one fewer byte
* `C` the first character in the input string
* `D`, `E` as `DE` the address of the current input character
* `H` the carry trigger (every 8th loop)
* `L` the output character being built up
[![enter image description here](https://i.stack.imgur.com/O0xT0m.png)](https://i.stack.imgur.com/O0xT0.png)
[Answer]
# J, ~~17~~ 13 Bytes
```
u:_8#.\2}.1{=
```
-4 thanks to FrownyFrog
Old version:
```
u:_8#.\2&({.i.}.)
```
### Explanation:
```
u:_8#.\2}.1{=
            =  | Self classify, for each unique element x of y, compute x = y, element-wise
          1{   | Second row
       2}.     | Drop 2
  _8#.\        | Convert non-intersecting subarrays of length 8 from binary
u:             | Convert to characters
```
Examples:
```
   = 'ABAABBAAAAAABBAAABAABBAABA'
1 0 1 1 0 0 1 1 1 1 1 1 0 0 1 1 1 0 1 1 0 0 1 1 0 1
0 1 0 0 1 1 0 0 0 0 0 0 1 1 0 0 0 1 0 0 1 1 0 0 1 0
   2}.1{= 'ABAABBAAAAAABBAAABAABBAABA'
0 0 1 1 0 0 0 0 0 0 1 1 0 0 0 1 0 0 1 1 0 0 1 0
   _8#.\2}.1{= 'ABAABBAAAAAABBAAABAABBAABA'
48 49 50
   u:_8#.\2}.1{= 'ABAABBAAAAAABBAAABAABBAABA'
012
```
[Answer]
# [Python 2](https://docs.python.org/2/), 77 bytes
```
lambda s:[chr(int(`map(s.find,s)`[i:i+24:3],2))for i in range(7,3*len(s),24)]
```
[Try it online!](https://tio.run/##NYzBCoMwEAV/JXhx0wYPUSgEeoi/oYJpNXWLbkJiD/36NJZ24PGYy/j3vjiSyV77tJrtNhkWVXdfAiDtMG7GQ6ws0iQiHztUeJaNqgchObcuMGRILBh6zHAR9WmdCSIXsuFD8uEolGX1dEhgc8@/duCZVOhW6zbv4Ps/b/@uiw8 "Python 2 – Try It Online")
[Answer]
# [R](https://www.r-project.org/), 71 bytes
```
function(s)intToUtf8(2^(7:0)%*%matrix((y=utf8ToInt(s))[-1:-2]==y[2],8))
```
[Try it online!](https://tio.run/##K/qfk5lUlFhUqaCRm1qSkZ9SrMmVpmCj@z@tNC@5JDM/T6NYMzOvJCQ/tCTNQsMoTsPcykBTVUs1N7GkKLNCQ6PSthQoEZLvmVcCVKkZrWtopWsUa2tbGW0Uq2Ohqfk/TUPJ0cnR0QmIQQBMQ/lOjkqa/wE "R – Try It Online")
Surprisingly golfy!
First, converts the string to ascii code-points with `utf8ToInt`, saving it as `y`. Removing the first two characters with negative indexing is shorter than using `tail`.
The array `y[-1:-2]==y[2]` is equivalent to the bits when `%*%` (matrix multiplication) is applied, but first we reshape that array into a `matrix` with `nrow=8`, converting from a linear array to byte groupings. Fortuitously, we can then convert to the ascii code points using matrix multiplication with the appropriate powers of 2, `2^(7:0)`, and then we convert the code points back to a string with `intToUtf8`.
[Answer]
# [Python 3](https://docs.python.org/3/), 77 bytes
```
a,b,*r=input();x=i=0
for c in r:i*=2;i|=a!=c;x+=1;x%8or print(end=chr(i&255))
```
[Try it online!](https://tio.run/##K6gsycjPM/7/P1EnSUeryDYzr6C0REPTusI209aAKy2/SCFZITNPocgqU8vWyDqzxjZR0TbZukLb1tC6QtUCKF1QlJlXopGal2KbnFGkkalmZGqqqfn/v6OTo6MTEIMAmIbynRwB "Python 3 – Try It Online")
[Answer]
# PHP, ~~73~~ 71 bytes
```
while($s=substr($argn,-6+$i+=8,8))echo~chr(bindec(strtr($s,$argn,10)));
```
Run as pipe with `-nR` or [try it online](http://sandbox.onlinephpfunctions.com/code/a7b0f18ec96488bd4e958230a52dd3ad7448f5b2).
golfings:
* start index at `-6` and pre-increment by `8`
* exploit that `strtr` ignores excessive chars in the longer parameter (no `substr` needed)
* translating to `10` and then inverting needs no quotes -> -1 byte
* invert character instead of ascii code --> `~` serves as word boundary -> -1 byte.
[Answer]
# Pyth, ~~20~~ 9 bytes
```
CittxLQQ2
```
Saved 11 bytes thanks to FryAmTheEggman.
[Try it here](https://pyth.herokuapp.com/?code=CittxLQQ2&input=%22ABAABBAAAAAABBAAABAABBAABA%22&debug=0)
### Explanation
```
CittxLQQ2
    xLQQ    Find the index of each character in the string.
  tt        Exclude the first 2.
 i      2   Convert from binary.
C           Get the characters.
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~82~~ 79 bytes
```
->s{s[2..-1].tr(s[0,2],'01').chars.each_slice(8).map{|s|s.join.to_i(2).chr}*''}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1664ujjaSE9P1zBWr6RIozjaQMcoVkfdwFBdUy85I7GoWC81MTkjvjgnMzlVw0JTLzexoLqmuKZYLys/M0@vJD8@U8MIpLKoVktdvfa/Y5B7GFgHSJFCQWlJsUJadHFs7f//jk6Ojk5ADAJgGsp3cgQA "Ruby – Try It Online")
[Answer]
# Japt, 11 bytes
```
¤£bXÃò8 ®Íd
```
[Try it](https://ethproductions.github.io/japt/?v=1.4.5&code=pKNiWMPyOCCuzWQ=&input=IkFCQUFCQkFBQUFBQUJCQUFBQkFBQkJBQUJBIg==)
---
## Explanation
```
¤               :Slice from the 3rd character
 £  Ã           :Map over each X
  bX            :  Get the first 0-based index of X in the input
     ò8         :Split to an array of strings of length 8
        ®       :Map
         Í      :  Convert from base-2 string to base-10 integer
          d     :  Get the character at that codepoint
```
[Answer]
## PHP + GNU Multiple Precision, 63 61
```
<?=gmp_export(gmp_init(substr(strtr($argn,$argn,"01"),2),2));
```
sadly the GMP extention is not default activated (but shipped).
Run like this:
```
echo "ABABABAAAAABABAAAAAABAABBAABAAAABBABAAABBB" | php -F a.php
```
[Answer]
# Java 8, ~~143~~ ~~142~~ 141 bytes
```
s->{char i=47;for(;++i<50;)s=s.replace(s.charAt(i%2),i);for(i=2;i<s.length();)System.out.print((char)Long.parseLong(s.substring(i,i+=8),2));}
```
-1 byte thanks to *@OlivierGrégoire*.
[Try it online.](https://tio.run/##LY/BasMwDIbvewpRGFgkNSNsrOB6kJy3XnocO7ium6pLnWA5hVHy7JmTRljYEr/k/7uYm1lfjr@jbQwzfBny9ycA8tGFk7EOdlMJcGvpCFbsYyBfA6NK3SFlOhxNJAs78KBh5PXH3Z5NANKv7@rUBqGyjLZvLwpZswyua9JawXISlVHQc4E54awkXSjasmycr@NZoML9H0d3lW0fZZd@jkJMY/jZ@lp2JrCbXmkZ9weerQnKKdMbzAtENYzqYbHrD02yuDidWa6JdMH5/jH4oPTSilVZlWWVcor5XuqqXC3Yw/gP)
**Explanation:**
```
s->{                            // Method with String parameter and no return-type
  char i=47;                    //  Index character, starting at 47
  for(;++i<50;)                 //  Loop 2 times
    s.replace(s.charAt(i%2),i)  //   Replace first characters to 0, second characters to 1
  for(i=2;i<s.length();)        //  Loop `i` from 2 upwards over the String-length
    System.out.print(           //   Print:
     (char)                     //    As character:
      Long.parseLong(           //     Convert Binary-String to number
       s.substring(i,i+=8)      //      The substring in range [i,i+8),
      ,2));}
```
[Answer]
# [Python 3](https://docs.python.org/3/), ~~99~~ 86 bytes
```
lambda s:[chr(int(str(list(map(s.find,s[i:i+8])))[1::3],2))for i in range(2,len(s),8)]
```
[Try it online!](https://tio.run/##NYxBCsIwEEWvkl1nMAi2mxJwkV4jZhFtYwfSachk4@mjFf3weLzNz6@67jy0eL21FLb7HJQY91gLEFeQWiCRVNhCBjlH4lmLI0On0SOiuxgzeN0jxr0oUsSqBH4u0Ou0MAjqEX3L5biK0NnJ2unDsa9/Pf3bdojtDQ "Python 3 – Try It Online")
Thanks to ASCII-only for basically the whole thing really
[Answer]
# APL+WIN, 30 bytes
Index origin 0. Prompts for input of string
```
⎕av[2⊥¨(+\0=8|⍳⍴b)⊂b←2↓s≠↑s←⎕]
```
Explanation:
```
s≠↑s←⎕ prompts for string and creates binary vector not equal to first character
b←2↓s drops first two elements of binary
(+\0=8|⍳⍴b)⊂ splits binary into groups of 8
2⊥¨ converts each group to decimal
⎕av[...] displays decoded characters
```
[Answer]
# [Red](http://www.red-lang.org), 110 bytes
```
func[s][t: 0 i: 128 foreach c next next s[if c = s/2[t: t + i]i: i / 2 if i = 0[prin to-char t t: 0 i: 128]]] 
```
[Try it online!](https://tio.run/##TYzBCsMgDIbvfYofr6PY9TQKO@gj7CoOilXqxQ61sLd3UXtYIAlJvi/RbuVlN6UHtxR3BqOSVnnBBL/gPj/gjmhXs8Mg2G/uJSnvaPFE4nOFM27wmgQPjhl09HSc1Cf6gHyMZl8jQX9vtdYoDkxIISRljdavWQo2VDuDvflYgw0dbxAh3Wq9i826ZtLLDw "Red – Try It Online")
## Explanation:
A simple straightforward solution, no builtins.
```
f: func [s] [                      ; s is the argument (string)
    t: 0                           ; total - initially 0
    i: 128                         ; powers of 2, initially 0
    b: s/2                         ; b is the second charachter
    foreach c next next s [        ; for each char in the input string after the 2nd one
        if c = b [t: t + i]        ; if it's equal to b than add the power of 2 to t
        i: i / 2                   ; previous power of 2
        if i = 0 [                 ; if it's 0 
            prin to-char t         ; convert t to character and print it
            t: 0                   ; set t to 0
            i: 128                 ; i to 128
        ]
    ]
] 
```
[Answer]
# Google Sheets, 123 bytes
```
=ArrayFormula(Join("",IfError(Char(Bin2Dec(Substitute(Substitute(Mid(A1,3+8*(Row(A:A)-1),8),Left(A1),0),Mid(A1,2,1),1))),""
```
Input is in cell `A1`. Google will automatically add `)))` to the end of the formula.
Explanation:
* `Mid(A1,3+8*(Row(A:A)-1),8)` grabs chunks of characters 8 at a time, starting with the third.
* `Substitute(Mid(~),Left(A1),0)` replaces each instance of the first character with 0.
* `Substitute(Substitute(~),Mid(A1,2,1),1)` replaces the second character with 1.
* `Char(Bin2Dec(Substitute(~)))` converts the chunk to decimal and then to ASCII.
* `IfError(Char(~,""))` corrects all the errors that result from the fact that `Row(A:A)` returns *far* more values than we so `Bin2Dec` gives us a lot of zero values and `Char` errors out on zero.
* `ArrayFormula(Join("",IfError(~)))` joins together all the `Char` results and `ArrayFormula` is what makes the `Row(A:A)` return an array of values instead of just the first value.
[Answer]
# [Haskell](https://www.haskell.org/), 75 bytes
```
f[_,_]=""
f(z:o:s)=toEnum(sum[2^b|(b,c)<-zip[7,6..0]s,c==o]):f(z:o:drop 8s)
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/Py06Xic@1lZJiStNo8oq36pY07Yk3zWvNFejuDQ32iguqUYjSSdZ00a3KrMg2lzHTE/PILZYJ9nWNj9W0wqiJaUov0DBoljzf25iZp6CrUJBUWZeiYKKgkaagpKjk6OjExCDAJiG8p0clTT/AwA "Haskell – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~61~~ 42 bytes
-19 bytes thanks to benj2240
```
->s{[s[2..-1].tr(s[0,2],"01")].pack("B*")}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1664Oro42khPT9cwVq@kSKM42kDHKFZHycBQSTNWryAxOVtDyUlLSbP2f0FpSbFCWrSSo5OjoxMQgwCYhvKdHJVi/wMA "Ruby – Try It Online")
[Answer]
# [Perl 5](https://www.perl.org/) `-lp`, 34 bytes
```
#!/usr/bin/perl -lp
s%.%1-/^$&/%eg;$_=pack'B*',s/..//r
```
[Try it online!](https://tio.run/##K0gtyjH9/79YVU/VUFc/TkVNXzU13Vol3rYgMTlb3UlLXadYX09PX7/o/39HJ0dHJyAGATAN5Ts5/ssvKMnMzyv@r5tTAAA "Perl 5 – Try It Online")
[Answer]
## REXX, 41 bytes
```
arg a+2 b
say x2c(b2x(translate(b,01,a)))
```
[Try it online!](https://tio.run/##K0qtqPj/P7EoXSFR20ghias4sVKhwihZI8moQqOkKDGvOCexJFUjScfAUCdRU1Pz////jk6Ojk5ADAJgGsp3cgQA "Rexx (Regina) – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), 88 bytes
```
i=input()
f=''.join('10'[x==i[0]]for x in i[2:])
while f:print chr(int(f[:8],2));f=f[8:]
```
[Try it online!](https://tio.run/##LYdBCsMgEADveYXkokIpqadg2YN@Y/FUurilrCKGpq@3aenAMEx991zEjcHAUrdu7ESg9flRWIy@LBp3AMYlJSpN7YpFMTqf7PTK/Lwr8rWxdHXLzRw1hH5NJ2ftlYBw9WmMOcQQ4uGXX/8fw/wB "Python 2 – Try It Online")
Not the shortest - just an alternative way.
Following version prints the output on one line for 98 bytes although the rules state that trailing whitespace is allowed.:
```
i=input();f=''.join('10'[x==i[0]]for x in i[2:]);o=""
while f:o+=chr(int(f[:8],2));f=f[8:]
print o
```
[Try it online!](https://tio.run/##LYzBCsMgEETv@QrxotJSUk/BsAf9jcVTqbiluCKWpl9vk9KB4THvMPXTMxc7BgGV@urarAmUujyYilbXWeEGQDjHmLiJTVARhNZFszJIOb0zPe8iOT7BLTdNpeuEbolna46jhIuLU227FzyG9MH7sPfIj/8dvPwC "Python 2 – Try It Online")
[Answer]
# [C# (Visual C# Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), 158 bytes
```
using System.Linq;a=>new string(a.Skip(2).Where((c,i)=>(i-2)%8==0).Select((c,i)=>(char)a.Skip(8*i+2).Take(8).Select((d,j)=>d!=a[0]?1<<7-j:0).Sum()).ToArray())
```
[Try it online!](https://tio.run/##RVBNS8QwED2bXxEPQqJtWfdisU2lFTwpCBX2sOxhSNM2u22iSaos4m@vqRvWDMN8vTfMC7cxt3yerFQdro/WiTF5luojQ4gPYC1@NbozMKJvhKwDJzn@1LLBLyAVsc542naHwXSWekhY8DQpnp@GET7FAreY4RlYocRX6BFI6oN8J2uabHphBCE8kpQVRMZrepUytqJJLQbB3XnCezA00NJreeOpb3AQJP1HNtHeI5tLBtvV7uE2z@/i/f2yaRoJ9XBdGgNHn84ZarURwHsclCx3YanOci6CnketrB5EsjHSCf87grQLg9IM/Sw2z2VVlpX35f3FUFflLw "C# (Visual C# Compiler) – Try It Online")
[Answer]
# [Perl 5](https://www.perl.org/) `-p`, 40 bytes
```
s/(.)(.)//;$_=pack'B*',eval"y/$1$2/01/r"
```
[Try it online!](https://tio.run/##K0gtyjH9/79YX0NPE4j09a1V4m0LEpOz1Z201HVSyxJzlCr1VQxVjPQNDPWLlP7/d3RydHQCYhAA01C@k@O//IKSzPy84v@6BQA "Perl 5 – Try It Online")
[Answer]
# [Scala](http://www.scala-lang.org/), 95 bytes
```
s.substring(2).replace(s(0),'0').replace(s(1),'1').grouped(8).map(Integer.parseInt(_,2).toChar)
```
[Try it online!](https://tio.run/##TY0xC8IwFIRn@ytClyZQQuvk4pA6Ofgb5DV9tpWaPPJSEcTfHqM4eHAc9w13bGGB5Psr2ihOMDuBj4huYGGIxLPY3GERLPaiNJ0xXfZH3/z1zpSJNa89xzC7UW6VDkgLWJQsG1VXTfVP2kzaTMbgV8JB7pS@Acmjizhi0ASBMRd5rvNQ9IcJgkr64gOCnSTli6iKV3oD "Scala – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), 124 105 93 bytes
```
f(x:_:y)=fromEnum.(/=x)<$>y
g[]=[]
g s=(toEnum.sum.zipWith((*).(2^))[7,6..0])s:g(drop 8s)
g.f
```
[Try it online!](https://tio.run/##dYqxCsIwGIT3PMVPcUhEojioBCMk4Obm4FCqFNomxbYJTQqtLx9jdfXgOL6707l7lk0TQoVH9mAT4VVv2nM3tBSv@UiOi9OEVJrxNEMKHMfezKOLftX2VnuN8ZJQvL0Tku5XO0o3GXFM4aI3Fg6OIM0VrUKb1x1wKAwCaEoPNoId/NX3l47qWFpIhBRCRn8054@lSL4HKf4ewhs "Haskell – Try It Online")
`f` converts the string to a list of bits by comparing each character to the first one, turning the `Bool`s into zeros and ones with `fromEnum`. `g` divides this list into groups of 8, converts them to decimal, and takes the value of the resulting number as an `Enum`, which `Char` is an instance of.
### Changes:
* -19 bytes thanks to @Laikoni (removing import, embedding `map` into function)
* -12 bytes inspired by @Lynn's answer (getting rid of `take` by zipping with shorter list)
[Answer]
# [Forth (gforth)](http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/), 83 bytes
```
: f over c@ 0 rot 2 do 2* over i 4 pick + c@ <> - i 8 mod 1 = if emit 0 then loop ;
```
[Try it online!](https://tio.run/##LYvRCsIwFEN/5bBHx2COPYhOsf2VrdcV3e6oxd@v7TQQQg6JaIhz85ASKZ0R9OMC452WoJGOSekOP@rp2fz4pC6D4UaT0YlFJ45c8YJbfMzPOLuVl@rGJb0rjDXGZhft@e/WVEj6Ag "Forth (gforth) – Try It Online")
Input is a standard Forth string (address and length) output is printed to stdout
## Explanation
```
over c@          \ get the value of the first character in the string
0 rot            \ add a starting "byte" value of 0 and put the length on top of the stack
2 do             \ start a loop from 2 to length-1
   2*            \ multiply the current byte value by 2 (shift "bits" left one)
   over          \ copy the reference char to the top of the stack
   i 4 pick +    \ add the index and the starting address to get address of the current char
   c@ <>         \ get the char at the address and check if not equal to the reference char
   -             \ subtract the value from our bit count, -1 is default "true" value in forth
   i 8 mod 1 =   \ check if we are at the last bit in a byte
   if            \ if we are
      emit 0     \ print the character and start our new byte at 0
   then          \ and end the if statement
loop             \ end the loop
```
]