[Question]
  [
*Inspired by [this video](https://www.youtube.com/watch?v=wdgULBpRoXk) by Ben Eater. This challenge forms a pair with [Encode USB packets](https://codegolf.stackexchange.com/q/229504).*
The USB 2.0 protocol uses, at a low level, a line code called [**non-return-to-zero**](https://en.wikipedia.org/wiki/Non-return-to-zero) encoding (specifically, a variant called [NRZI](https://en.wikipedia.org/wiki/Non-return-to-zero#Non-return-to-zero_inverted)), in which a stream of bits is encoded into a stream of two electrical level states `J` and `K`. Decoding works as follows:
* Start with some initial state, which is either `J` or `K`
* For each state to be decoded:
	+ If the state is different to the previous state, write a 0.
	+ If the state is the same as the previous state, write a 1.
For this challenge, we will assume the encoding starts in state `J`.
However, it's not that simple: an additional process called [**bit stuffing**](https://en.wikipedia.org/wiki/Bit_stuffing) takes place, which is designed to make it easier to detect if the signal has dropped out. After 6 consecutive 1 bits are written, a meaningless 0 bit is written to ensure the signal never stays in the same state (`J` or `K`) for too long. When decoding, you need to take this into account and remove the 0 bit that necessarily occurs after 6 consecutive 1s.
The full USB specification is available [here](https://usb.org/document-library/usb-20-specification) on the USB website, or mirrored (and easier to access) [here](https://eater.net/downloads/usb_20.pdf), but I'd caution you before reading it because it's extremely long and the pertinent information is hard to pin down.
## Task
Given a non-empty list of `J`s or `K` states as input, decode the string using the USB implementation of NRZI described above, and output a binary string.
You may assume the input will never contain invalid data with incorrect bit stuffing (i.e., it will never contain 7 consecutive 1s).
## Test-cases
```
Input              Output
=====================================
J                  1
K                  0
JKJKKJJ            1000101
KJKJKJKJ           00000000
JJJJJJKKK          11111111
KJJJJJJKJ          001111100
KJJJJJJJKJK        0011111100
KJJJJJJJKKJK       00111111100
KJJJJJJJKKKKKKKJKJ 0011111111111100
KJJJJJJJJKJ        (incorrect bit stuffing; does not need to be handled)
KJJJKKKJKJJJJKJJ   0011011000111001
KKKJJKJKJJJJKKJKJJJJKKJKJJJJKJKJKKKKJKKKJKKKKJJKJKKJJJJJKJJKKKKKJJJJKKKKJJJJKKKKJJJJKKKKJKKJJJJKJJJJJKJJKKKJJJJJKKKKJJKKJJJJKKJKJJJJKKJJKKKJKJJKJJJKJJKKJKKJJJJKJJJKJKKKJJJKKKKKJJJKKKJJKJJKKKKKJJJJKKKKJJJKJKJJKKKKJJKJKKKJKJJJKKKJJKJKJKKKKKKKJKKKKJJJKJKKKKKJJKKKJKKJKJJKKJKJJKKKKJJJJKJJJKKJKJJJJKKKKJKKKKJKKJJKKJJJJKKKJKKKKJJKKKJKJKKKJKJJJKKJJKJKK   01101000011101000111010001110000011100110011101000101111001011110111011101110111011101110010111001111001011011110111010101110100011101010110001001100101001011100110001101101111011011010010111101110111011000010111010001100011011010000011111101110110001111010110010001010001011101110011010001110111001110010101011101100111010110000110001101010001
```
## Rules
* The input should be a string or array, with the two states `J` and `K` being represented by two distinct values of your choice ([within reason](https://codegolf.meta.stackexchange.com/a/14110))
* The output should be a string or array of `1`s and `0`s or of `true`s and `false`s
* You may use any [standard I/O method](https://codegolf.meta.stackexchange.com/q/2447)
* [Standard loopholes](https://codegolf.meta.stackexchange.com/q/1061) are forbidden
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes wins
  
[Answer]
# [convey](http://xn--wxa.land/convey/), 31 25 bytes
Takes `JK` as `01`.
```
>="*>0
",v+<"(6
{0>">>!`}
```
[Try it online!](https://xn--wxa.land/convey/run.html#eyJjIjoiPj1cIio+MFxuXCIsdis8XCIoNlxuezA+XCI+PiFgfSIsInYiOjEsImkiOiIxIDAgMCAwIDAgMCAwIDAgMSAxIDEgMSAxIDEgMSAwIDEgMCJ9)
Compares `=` the string with itself with a `J` prepended `,0`. The middle loop just adds the comparisons to a counter (starting with 0) that gets reset on a 0. Only take `!` elements where the previous counter was less than 6 `(6`.
[![enter image description here](https://i.stack.imgur.com/nUF0L.gif)](https://i.stack.imgur.com/nUF0L.gif)
[Answer]
# [Husk](https://github.com/barbuz/Husk), 11 bytes
```
σḋ126ḋ63Ẋ=Θ
```
[Try it online!](https://tio.run/##yygtzv6fq/FwZ2Pxo6bGIs1D2/6fb364o9vQyAxImhk/3NVle27G////ow1iuaINgdhAx1AHhEEkWEwHJgLGYBUICFJnCFWFLGqAIQY1Aas4PhkExGUuujiSaiSbISqg/sKQJ8RHhIohEgtZBCXckO1F8QGqvwjzDdF9gcVkA6zmGBL0H3pIGWKYjd1@QzSb0f2HGiKE/W@IoRLdFuwmG2JNIZgmo4eKIVqIGOJwgQGazQY4Ywg1rDB9aoDDDdh9iOTyWC4A "Husk – Try It Online")
Takes an array of bits(0=J, 1=K), outputs an array of bits(formatted as string for convenience)
## Explanation
```
σḋ126ḋ63Ẋ=Θ
          Θ Prepend 0
        Ẋ=  map overlapping pairs by equality
σḋ126ḋ63    replace binary digits of 126 with binary digits of 63 (stolen from Luis Mendo)
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~15~~ 14 bytes
```
0ihd~126B63BZt
```
Input is an array with `0` for `'J'` and `1` for `'K'`.
[Try it online!](https://tio.run/##y00syfn/3yAzI6XO0MjMyczYKark//9oAwUENATBWAA) Or [verify all test cases](https://tio.run/##hVJLCsIwFNx7ihzhjUIPUDyCC7EUFF0o6K5rrx5NTMn7xRBeaSbDTGba12V5xnOkx/32xnYYh914WiJdj/tDnGjeTPgOBYQ06ZmxsCJ5MqOuxENhcZQMVhRc/N9JXS1djTM2c/4xSi5z3tvXVsDeOCJ6474igczV30OncJTJ1UE3n24KRtv3h3LW@WQj/fwwTO3iK8P9Q6yybgWqETRuQMqZml9IdmWTUuMOfkJ28/kD).
### Explanation
```
0       % Push 0
i       % Input: string
h       % Concatenate
d       % Consecutive differences
~       % Negate: converts nonzero to 0, and zero to 1. Gives a numeric vector (*)
126B    % Push 126, convert to binary. Gives [1 1 1 1 1 1 0]
63B     % Push 63, convert to binary. Gives [1 1 1 1 1 1]
Zt      % String replace (works for numeric vectors too). Replaces [1 1 1 1 1 1 0]
        % by [1 1 1 1 1 1] in (*)
        % Implicit display
```
[Answer]
# JavaScript (ES6), 54 bytes
```
s=>s.replace(/./g,a=>s^(s=a>"J")?i=i>5?'':0:++i/i,i=0)
```
[Try it online!](https://tio.run/##dVRNb8IwDL33V1RcSARr3cMuQymnXeLjjmMTVVdYpkIrUk1I034764edhlYzVIa8Z79nB/GVfWc2v5i6eThXH8XtoG5WpTa6FHWZ5YWIo/i4ztqTd2FVli70Qm6NMunjdrl8gqfVysRmbRTIW1PYJs9sYUMV7gMdziIJcH4IgUaNqO/4CQAk0PL18PL5FIHuA9HrmVC0dQOo/boeagsJ7BpPwDt0hBm9h/voJBzscwasV9HUonv3XOgm60ZmyjT3G0HU9AxMJNODNHuYZWRVR9YjB6d67BOZ7dUjFbMeGZnpIx9yiUfGcVGOzFaQjKDXgJSdQcRxKieqvQ6e4NC8W3a3a6BdJ5MM7g4SD4Dh6ij/9wAn98XjQzLR4wsnKfDrgX8QVE@WZ/rA5qjvWMeD3HETUu5bkSb4/j1/PD943t1KSJn1hqpgHzUXcxIysnVpGrHcnZcyOmW1uIYqDa/txyb/FPHuZRUfpdwE7h8hOlSX56zFxKtZF29SpT9BXp1tVRZRWR3FQRipVLHusgx@5eb2Bw "JavaScript (Node.js) – Try It Online")
Take input as a string of "J" / "K". Output a string with "0" and "1".
And `f=J=>J.replace(/./g,a=>J^(J=a>f)?i=i>5?'':0:++i/i,i=0)` is 54 bytes too.
---
# JavaScript (ES6), 44 bytes
```
s=>s.flatMap(a=>s^(s=a)?i=i>5&&[]:++i>0,i=0)
```
[Try it online!](https://tio.run/##dVTBbuMgFLz7K3yqQcnS50MvrXBPe@FpT3tMs6rldVqq1ETBiiqt9tuzYB6Y2FoSh9gz82Z4WHy0l9Z2Z30avw3md389yKuVjRWHYzv@aE@sdTe/mJUtf9ZSNw93d7v942ajG9hqCfw69nbsWtvbUpavhSpXoy5w/RAKhQpR3fBrAKjB8VX45HwahZoGYlazpuF0AVS5boKckEBfeAHeoDMc0Vt4Gt4iwTknYJOLohL@O3HBr8wvOVKW89QRREVXYCKFDtYxw2rG6JrIaubg0i/mxMjO9Eji6EdBVv4YH0ZJRsa5UYkcoyAFwawAOaeAiPOqkqnKKmSGobhvtu81UK/rxQxpD@oMgLB1NP/vgjilm4wP9cIvbjhZQa6H@EKQniKv/CGGo7qzLi7khluT81SKPCHPn@WL64cse2oJOUe/oCpexXjWn4wLezrqkVUvQ8XFpzsavkrZlF/u79i9s/uXn5v7N86finQiiIM5f28dxnZ62@@5bP4UF3dM7IQQej@V6HwJ9yPLCiunNQ4@sEuoP3hwM3DxYfTAKo93ZrDm2IujeWNGyn5rePGXP13/AQ "JavaScript (Node.js) – Try It Online")
Take input as an array of false (for "J") and true (for "K"). Output an array of false and true.
[Answer]
# [R](https://www.r-project.org/), ~~83~~ ~~76~~ 62 bytes
```
function(x)gsub('(1{6})0','\\1',Reduce(paste0,+!diff(c(0,x))))
```
[Try it online!](https://tio.run/##K/qfZvs/rTQvuSQzP0@jQjO9uDRJQ13DsNqsVtNAXUc9JsZQXScoNaU0OVWjILG4JNVAR1sxJTMtTSNZw0CnQhMI/qdplJakWYTke@aVaKh7qWvqmptocqEIemMT9PL28vb2wq7eCwKxagMDb29v7Bohsl54JEEm45WGADyGQGTBJkHV/AcA "R – Try It Online")
Takes input as `0`(`J`) and `1`(`K`).
Outputs string of `1`s and `0`s.
Change of approach after looking at [@Luis Mendo's answer](https://codegolf.stackexchange.com/a/229385/55372).
```
function(x)    # function taking x as input
gsub(          # replace all occurences of
'(1{6})0',     # 6 ones and a zero
'\\1',         # with just 6 ones (first capturing group)
Reduce(paste0, # in a following vector collapsed to string
+!diff(c(0,x)) # negated differences of x with 0 prepended 
               # converted from logical to numeric with unary +
               # this would be the output without bit stuffing
))
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~79~~ 76 bytes
-3 thanks to @ceilingcat
```
x;c;a(char*p){x=74;for(c=1;c*=*p==x,x=*p++;c=c>5?x=*p++,1:c+1)putchar(!!c);}
```
[Try it online!](https://tio.run/##dVLrasIwFP7fp8gKY23tMIGNwUq3/zmvIGwlq1OGtWiEgvjsLpdzaow1Wk6afrckRz3/KnU@D5Wqmkytml3R58ehfnuplttdpmpRqaIu@roeysHU2axStfp4/fQvpXhXM5H3B22p2cODyqvTed1pptu99npse9Al89N1lyfHhJnRZGZeuWm/M4Rlli66x/2iW3RpaRjm2ylJrNKmWXcZ0eYF081fu2d61TKTcNNo9u282qFvlW5/vgy5t47rzpT8iRVzx3SgVKQlS2WKzn6N2zW4XhOcc8E9GiSAjDk4HFX6X6SAw0m4AQCxiEOQigfJScw1yNpNw2LcfeAk2o3JDPbvuNyfCni8BB8nZlgCR4KIKh@FRPCB@zxY7z2cyvgS4LmI/Cg1WvGQz2lXyMfIN/6cwqHuhUcbucIKdHZS6MnD/EE@2j8Pso9Hgs7k51nu5G030sHH1TUrgMTHIwF7xl8w3fRNBbrLESwvGIj96PaB0AEfkEx@GOTGH2iRKAEYLu04gikKYBAIBNB5DAhw2dVoKgOFwNCL2xY@nf8B "C (gcc) – Try It Online") Takes input as `J` and `K`, outputs with bytes `0x00` and `0x01` for `0` and `1`.
For output as numeric `0` and `1`,
[Try it online!](https://tio.run/##dVLrasIwFP7vU2SFsbZWTMAxttLtf84rCFvJ6izDWjRCQXx2l8s5NUYXLSdNv1uSo2Y/Sp3PQ6nKOlXrepf32XGoXhblartLVSVKlVd5X1VDMZg6nZaqUu/PH/6lEG9qKrL@oC01XbzOHlRWns5tp5lu9torsu1BF8xP2y6bHCfMjDo189JN@50hrNJk2T3ul92ySwrDMN9Ok4lV2tRtlxJtnjNd/zZ7ptcNMxk3tWZfzqsZ@kbp5vvTkHvr2HamZE8snzumAyUiKVgiE3T2a9yuwfWa4JwL7tEgAWTMweGo0v8iBRxOwg0AiEUcglQ8SN7FXIOs3X1YjPsfeBftxt0M9u@43J8KeLwEHydmWAJHgogqH4VE8IH7PFj/eziV8SXAcxH5UWq04iGf066Qj5Fv/DmFQ90LjzZyhRXo7KTQk4f5g3y0fx5kH48EncnPs9zJ226kg4@ra1YAiY9HAvaMv2C66ZsKdJcjWF4wEPvR7QOhAz4gmfwwyI0/0CJRAjBc2nEEUxTAIBAIoPMYEOCyq9FUBgqBoRe3LXw6/wE "C (gcc) – Try It Online") for 78 bytes.
[Encoder](https://codegolf.stackexchange.com/a/229567/80050)
[Answer]
# [J](http://jsoftware.com/), 26 bytes
Takes in `JK` as `0 1`.
```
t#~0=_6|.(6$1)E.t=:2=/\0,]
```
[Try it online!](https://tio.run/##lVQ9T8QwDN37KyJAylXqFYfhhqJOCIaYiRVODOiuwMJyI@Kvl7aJm8ROOJGotdz6veePtJ/jRauPqu@UVo0C1U3XtlV3T48P4@nyB/rX3Xe72V2Z@r499d1Nf/0CzX6sq6Hvnrujtqg/2n11eHv/UpvN7VArjdYtdMui1bUPGJSeHLXtlFyNCUFYDIKIaaKetGSomWqY92xjUuu2AEC6IwWqg0NMumMNBxEiLh/aicraL8t0UkwJxWEcVcSF6SxoifuDwSGXpEOpxED3wAhsEvPciIDbZayI1l8uEn2HXNqUv7BIOa3BNsQg16MqkKIjPHow6flEhD7SQ4JEwRiavAZTKugTwYjAK68JIoaqVlEbMUSCjjwaBQ0C2CDMGR/k4CKbIiA@IMz/rwXhyTd5fhA@FN6HvIFx5/VBHOlUP@3y@fpBdA6YCmSZIfMrMIVPjdebTiunn1Ys@8fnD4W@m0zf0/MHTGd9Uo2/ "J – Try It Online")
```
t#~0=_6|.(6$1)E.t=:2=/\0,]
                       0,] prepend a J
                   2=/\    pair-wise equal
                t=:        store as t
         (6$1)E.           bitmask of places where 6 ones starts
     _6|.                  shifted by 6 bits
   0=                      negate
t#~                        take only truthy bits from t
```
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal), 16 bytes
```
1p-Ṫv¬ṅ\16*:0+$V
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=1p-%E1%B9%AAv%C2%AC%E1%B9%85%5C16*%3A0%2B%24V&inputs=%5B1%2C1%2C1%2C1%2C1%2C1%2C0%2C0%2C0%5D&header=&footer=)
```
1p               # Prepend a 1
  -              # Differences - truthy if unchanged, falsy if changed
   Ṫ             # Get rid of last
    v¬           # Vectorised not
      ṅ          # Joined
       \16*      # Six ones
           :     # Duplicate
            0+   # Append a 0 to the first
              $  # Swap
               V # Replace
```
Takes the difference of the list with a 1 prepended and the list itself, NOTted, to get the values. Then spend the remaining 10 bytes on doing the bit stuffing.
[Answer]
# [PHP](https://php.net/) -F, 96 bytes
```
for($s=$r=$argn;$s[++$i]!='';)$r[$i]=+!abs($s[$i]-$s[$i-1]);echo str_replace(1111110,111111,$r);
```
[Try it online!](https://tio.run/##K8go@G9jXwAk0/KLNFSKbVWKbFUSi9LzrFWKo7W1VTJjFW3V1a01VYqigWxbbcXEpGKgMhBHF0zpGsZqWqcmZ@QrFJcUxRelFuQkJqdqGIKBgQ6E1lEp0rT@/x8qaGDwL7@gJDM/r/i/rhsA "PHP – Try It Online")
Well, I.. tried.. to make it short.. hum!
takes a string of 0 (J) and 1 (K) as input
[Answer]
# [Python 2](https://docs.python.org/2/), 77 bytes
```
lambda s:''.join((`+(x==y)`for x,y in zip('J'+s,s))).replace('1'*6+'0','1'*6)
```
[Try it online!](https://tio.run/##TcYxDsIgFAbgq7D97wlpqIODSS8AV@hQ1BIxlRLoULw8Jnbxm75Ut@caz80PY1vc@/ZwolyB7rWGSDRJ2oeh8uTXLHZVRYjiExLBQBZVmLnLc1rcfSb0OF0kNNRv3FIOcSNPsOZgD8YasILW/R@twe0L "Python 2 – Try It Online")
-2 bytes thanks to @ovs
[Answer]
# [Red](http://www.red-lang.org), 79 bytes
```
func[x][p: s: 0 collect[foreach i x[s: any[all[s < 6 keep p = i s + 1]0]p: i]]]
```
[Try it online!](https://tio.run/##jZHBaoQwEIbveYoh16WQQNmCti9gbr0Oc5BsZENFRbOwfXo7Gd1WbQ/9lRz8v29GyBgu83u4IKmmmJtb5/FOOBQwFWDA920bfMKmH0PtrxDhjlzU3SfWbYsTvMIZPkIYYIA3bic4gSVD7EcimmMBj5HHUZ5Hifn08syWZ1z1/8BDTNcwgkdLaChbDyQBKl1p@JXSKu3@@m6Yd5Vz1d4qrTHGmmxVy6N31hqWJc5th5d2TbaXfquzLW3W1z5v0Md@D2yIb@BASGTXD7HDllrWyQ8Jll/B@VB872PsEvTQ8F0mmr8A "Red – Try It Online")
Takes input as a block of \$1\$s and \$0\$s, outputs a block of booleans.
Test suite on TIO uses two additional transformation functions that allow reading inputs from JK-strings as in task specification and convert output to numbers for nicer visualization.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~13~~ 12 bytes
*-1 thanks to [Kevin Cruijssen](https://codegolf.stackexchange.com/users/52210/kevin-cruijssen).*
```
0ìüQJƵPbD¨.:
```
[Try it online!](https://tio.run/##yy9OTMpM/f/f4PCaw3sCvY5tDUhyObRCz@r/f0NDQwMDQyAEAkN0GgRBCqAYohIsBVJgCBEyMMBKQ5lIig0QagzR7YNYAVEPkUfoN4RqhtkHdQiG/YYwQZgWJMUQ9yP8AROAWmwIsxTJEygONDRE@ApuqQGSCUgWQgwHAA "05AB1E – Try It Online") Uses `0` for `J` and `1` for `K`.
```
0ìüQJƵPbD¨.:  # full program
          .:  # replace all instances of...
     ƵP       # 126...
       b      # in binary...
          .:  # in...
    J         # joined...
  ü           # are all digits of each element in...
0             # literal...
 ì            # concatenated with...
              # implicit input...
   Q          # equal...
          .:  # with...
      ƵP      # 126...
        bD    # in binary...
          ¨   # excluding the last digit
              # implicit output
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 19 bytes
```
⪫⪪⭆θ⁼ι§⁺Jθκ⁺×1⁶0×1⁶
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMMrPzNPI7ggJ7NEI7gEKJLum1igUaij4FpYmphTrJGpo@BY4pmXklqhEZBTWqyh5KWko1CoqaOQrakJJMFiIZm5qUAZQ6CMGVBMyUAJJIUiqqlp/f@/txcEeEOAl7fXf92yHAA "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
   θ                Input string
  ⭆                 Map over characters and join
        J           Literal string `J`
       ⁺            Concatenated with
         θ          Input string
      §             Indexed by
          κ         Current index
    ⁼               Equals
     ι              Current character
 ⪪                  Split on
             1      Literal string `1`
            ×       Repeated
              ⁶     Literal `6`
           ⁺        Concatenated with
               0    Literal string `0`
⪫                   Join with
                 1  Literal string `1`
                ×   Repeated
                  ⁶ Literal `6`
                    Implicitly print
```
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 16 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
Å3≈àE∩◄σ←π<δô╝ìà
```
[Run and debug it](https://staxlang.xyz/#p=8f33f78545ef11e51be33ceb93bc8d85&i=%5B0%5D%0A%5B1%5D%0A%5B0,+1,+0,+1,+1,+0,+0%5D%0A%5B1,+0,+1,+0,+1,+0,+1,+0%5D%0A%5B0,+0,+0,+0,+0,+0,+1,+1,+1%5D%0A%5B1,+0,+0,+0,+0,+0,+0,+1,+0%5D%0A%5B1,+0,+0,+0,+0,+0,+0,+0,+1,+0,+1%5D%0A%5B1,+0,+0,+0,+0,+0,+0,+0,+1,+1,+0,+1%5D%0A%5B1,+0,+0,+0,+0,+0,+0,+0,+1,+1,+1,+1,+1,+1,+1,+0,+1,+0%5D%0A%5B1,+0,+0,+0,+0,+0,+0,+0,+0,+1,+0%5D%0A%5B1,+0,+0,+0,+1,+1,+1,+0,+1,+0,+0,+0,+0,+1,+0,+0%5D%0A%5B1,+1,+1,+0,+0,+1,+0,+1,+0,+0,+0,+0,+1,+1,+0,+1,+0,+0,+0,+0,+1,+1,+0,+1,+0,+0,+0,+0,+1,+0,+1,+0,+1,+1,+1,+1,+0,+1,+1,+1,+0,+1,+1,+1,+1,+0,+0,+1,+0,+1,+1,+0,+0,+0,+0,+0,+1,+0,+0,+1,+1,+1,+1,+1,+0,+0,+0,+0,+1,+1,+1,+1,+0,+0,+0,+0,+1,+1,+1,+1,+0,+0,+0,+0,+1,+1,+1,+1,+0,+1,+1,+0,+0,+0,+0,+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,+0,+0,+1,+1,+0,+1,+0,+0,+1,+1,+1,+1,+0,+0,+0,+0,+1,+0,+0,+0,+1,+1,+0,+1,+0,+0,+0,+0,+1,+1,+1,+1,+0,+1,+1,+1,+1,+0,+1,+1,+0,+0,+1,+1,+0,+0,+0,+0,+1,+1,+1,+0,+1,+1,+1,+1,+0,+0,+1,+1,+1,+0,+1,+0,+1,+1,+1,+0,+1,+0,+0,+0,+1,+1,+0,+0,+1,+0,+1,+1%5D%0A&m=2) doesn't work since stax auto-replaces null bytes with spaces.
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 25 bytes
```
*|+(126=2/')_7':(&6),0=':
```
[Try it online!](https://ngn.bitbucket.io/k#eJyVU8tOxDAMvPcrohxoC5Vw9rBIlVZwznwEtz3tJyC+nTaO87BbEIlay8mMx3br+/r89TKFy/V2eR3nz7dxnZ6u80K3cR2Gx+oj/PswLWH+vrvHx+Kj3zwSD34IjtLebdiPN0oE4gYk1+10ich7J3abqWkBYHK9rnRGRA0wkF3Fgg5gJ7jfGGl1Sci7xqHSDzAngrNKLOGQ4ugYNqbRaGzPqBVZ/7+WjGdvjuOT8XW2unt9VeTO9Mnp7vf6fZf/rp+c7hwpFaunv8h53NDFbOvr69T6fcW2f/r7tz21eRzlcFxfo8V/8T7T8hNrm0YeiPlhJPIY8sDI5BgLmYsCjhUDrSeTBEE3fGSy6OVEjD7kUCgNGHW8C1hSQU4ETYCsXBIEalVFNDYRGkEO7n8ANZIiBQ==)
Takes `J` as `0`, and `K` as `1`. Returns a list of `0`s and `1`s.
* `0=':` run an equals-each-prior, seeded with `0` on the (implicit) input, handling the non-return-to-zero part
* `7':(&6),` prepend 6 `0`s to the input, then slice into length-7 sliding windows. the first 6 slices will contain some dummy `0`s
* `(126=2/')_` drop chunks of `1 1 1 1 1 1 0`, i.e. where the last value in the chunk is a dummy `0` inserted for bit stuffing purposes
* `*|+` return the last value of each chunk (saves a byte over `*'|'`)
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 61 bytes
```
n=>n.replace(/./g,(e,i)=>1-e^n[i-1]).replace(/1{6}0/g,111111)
```
[Try it online!](https://tio.run/##dVTBboMwDL3zFbkVtLY4l10m@gHxJzCmoi6rOjFALdpl2rczktjBgGZAUfKe/V4c4LP@rh@X@60fDm33bsePYmyLU3u8276pLzbNj/l1n9r9LStO@mDf2vJ20FU24/rn@RcmjvaRjZeufQxqUIU6G7UJneB2ERKDBtEs@BoANEx8Ey7Jp0iMD0RRU1NMeQE0Ms9DUyKBrvAKXKAzzOgS9uEkIiw5AfMqhkq423PB7cxtmSnr0XcE0dATmEimgzR72IzIqpFsZg6u9dgnMlvkIyWzHhnZ6CMvcoog49yoSGYrSEZQFCDlaBBx3lUUNaKCEAzFXbNdr4F6rVcjxDPQAoBwdDT@9wAPcSL4oFd6fOAkBTIf@IWgfLK80Qc2R3XnPN7IgqtJ2ZciTZD@hT/ePwjvsSWkzHoh65yo@dM302cPmVxB9yNwK4@@uQ3p7rXdudlX3ae2UcVJ2YagXD3lWfaSuN9F19hj013TQRBL25S62quPaV5ClVUTefwD "JavaScript (Node.js) – Try It Online")
I have tried to make sure it outputs numbers.
-10 bytes by pxeger
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 14 bytes
```
Ż⁼Ɲ0ȯ1×‘ʋ7Ƒ?ɼƇ
```
[Try it online!](https://tio.run/##ZVAxDoIwFN05C4NMju7/ncAYRxfDBdjQhcFJFxnkBkZj4mJgIxD1FvQitbT9pUKb5r/@vP/ea7ebOE6kbEqxq9pi9r5H9Vmk@fcwb4@LT9VmsiufIr0QRFqEq1kYrRPxuNWZ2F@bU/fKVV1KSQECAgGkEJkdkF4AVMtAYtQTBvx/0Yu5BuoB1ej1@T6u2h4gewwT1szIsv6kgi0cmQYOxn4cCsz25mGH2c8GmfiDmzzikTF8giNzFNgg8ASsswsIDK9ypuQpeIZG/Ac "Jelly – Try It Online")
Takes `J` and `K` as `0` and `1`.
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 31 bytes
```
(.)(?<=(\1.|^J)?)
$#2
1{6}0
6$*
```
[Try it online!](https://tio.run/##ZZCxDsIwDER3/wZFShgqytAJ1BHJ9wsIwcDAwoDYgG8PbWwnpk1V5Wyd/a593l73xzWtw/GSQhvDsD@EU9d@zhyHSM1qR927/26pbzYpMYEYDPCoWB7ifACMLZFsajJU/V/k472mpZ3rsTGxrJ7fOQrA@ooTuksQxlrcMEQxc/VgzrNQMLebhw4bT4Ms@LCmjTgz6g8pZosCDQK3QMklIFC/qkDZbXBAWf4D "Retina 0.8.2 – Try It Online") Link includes test cases. Explanation:
```
(.)(?<=(\1.|^J)?)
```
For each letter, look behind for a possible duplicate or a leading `J`.
```
$#2
```
If it was then replace it with a `1` otherwise replace it with a `0`.
```
1{6}0
6$*
```
Remove the `0` that appears after a run of six `1`s.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 14 bytes
```
ŻI¬“~?‘B¤œṣjƭƒ
```
[Try it online!](https://tio.run/##y0rNyan8///obs9Dax41zKmzf9Qww@nQkqOTH@5cnHVs7bFJ//3jzU0Ot///7@0FAd4Q4OXtBQA "Jelly – Try It Online")
A monadic link taking the argument as a vector of 0 (=J) and 1 (=K) and returning a vector of 0 and 1.
]