[Question]
  [
*Golfeek* is the working name of an esolang I'm occasionally working on. One distinctive feature of this language is that each statement is encoded as a sequence of bits rather than a sequence of bytes.
Instead of just showing a long binary sequence, the 'gutter' of the source editor contains a representation of each statement in a more digest and (slightly) more readable format:
[![example Golfeek source code](https://i.stack.imgur.com/C3S6e.png)](https://i.stack.imgur.com/C3S6e.png)
## Format
* The binary sequence is always read from left to right.
* It is first split into nibbles (groups of 4 bits) shown as uppercase hexadecimal between brackets. A space is inserted after each byte, provided that it's followed by another byte or a last lone nibble.
*Example:*
```
[1,1,1,1,0,0,0,0,1,0,1,0] --> "[F0 A]"
 \_____/ \_____/ \_____/
```
* If there are more than 14 nibbles, only the first 6 bytes are shown, followed by a space, followed by `..`, followed by the closing bracket.
* If the number of bits is not a multiple of 4, the remaining bit(s) is/are appended as '0' or '1' right after the closing bracket.
*Example:*
```
[0,1,1,1,1,0,0,1,0,1] --> "[79]01"
 \_____/ \_____/ \_/
```
## Your task
Given a sequence of bits, return its representation in *Golfeek* format.
## Rules
* The sequence of bits may be taken in any reasonable and non-ambiguous format. Please note that the sequence may contain leading zeros, which your format must be able to deal with.
* You can assume that there will always be at least 4 bits in the input sequence, and therefore at least one nibble between the brackets.
* The output must be a string (or a list of characters) that conforms exactly to the format described above, with uppercase hexadecimal and correct spacing. A trailing linefeed is optional.
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'").
## Test cases
### Input
```
0101
00001
110101
10100111
101001111100
000000000000000
011110101101001110010011000111
11011110101011011011111011101111
11110101000110000001111011001110011100100110111000100000100
111101010001100000011110110011100111001001101110001000001001
1111010100011000000111101100111001110010011011100010000010010
```
### Output
```
[5]
[0]1
[D]01
[A7]
[A7 C]
[00 0]000
[7A D3 93 1]11
[DE AD BE EF]
[F5 18 1E CE 72 6E 20]100
[F5 18 1E CE 72 6E ..]
[F5 18 1E CE 72 6E ..]0
```
  
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~36~~ ~~34~~ ~~33~~ 31 bytes
```
Ć4ô¤¨s¨Ch2ôJDg8@i6∍„..ª}ðý"[ÿ]ÿ
```
[Try it online!](https://tio.run/##yy9OTMpM/W9o6Pb/SJvJ4S2HlhxaUXxohXOG0eEtXi7pFg6ZZo86eh81zNPTO7Sq9vCGw3uVog/vjz28/7@S/X8DQwNDLgMgMOQyNARzQKSBoSGCARQ3ACtBAlxgCZB6mCoDCG0A1WsIVwBWYgg1CIpBCqCyUE0QfWCVUNMQRhpCjIUoAtpNgV6KLDY0AAA "05AB1E – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 35 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
s4µLÐṀ©s14Ḅ‘ịØHUḢaȧ⁾..$ƊUs2KØ[j;ḟ®F
```
A full program which, given a list format of 1s and 0s, prints the result.
**[Try it online!](https://tio.run/##y0rNyan8/7/Y5NBWn8MTHu5sOLSy2NDk4Y6WRw0zHu7uPjzDI/ThjkWJJ5Y/atynp6dyrCu02Mj78IzoLOuHO@YfWuf2////aEMdBTgyQCUNYGxkLpo4skZDDClcXDSTDTFsMcRmHYgRCwA "Jelly – Try It Online")** Or see the [test-suite](https://tio.run/##y0rNyan8/7/Y5NBWn8MTHu5sOLSy2NDk4Y6WRw0zHu7uPjzDI/ThjkWJJ5Y/atynp6dyrCu02Mj78IzoLOuHO@YfWuf2/@HuLf4PdzQdbn/UtCby/391dfUYLgNDA0MuAyAw5DI0BHNApIGhIYIBFDcAK0ECXGAJkHqYKgMIbQDVawhXAFZiCDUIikEKoLJQTRB9YJVQ0xBGGkKMhSgC2k2BXoosNjQABhkA "Jelly – Try It Online").
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), ~~112~~ 111 bytes
```
.{4}
$& 
(.+) 
[$1]
T`d`L`.*]
B
AB
+`BA
ABB
A+(B*)
$.1
T`d`L`1\d(?=.*])
B(.)
$1
T` `_`\w..
(\[.{18})...+]
$1..]
```
[Try it online!](https://tio.run/##pY0xCwIxDIX3/IobDmkthAQcXESus6PbXbHCObg4iOBw3G@vaRs99wu0Sfu@9/K8ve6Pa0o47WZoNw0YdLaBvuUA5zjGU8RtAA@dBxd9J11mZ/zWQousCA@jOR4EtOANipKFJl7i8EYEM/Q48X62iOiCiIghJWJiICkG5vLINzEvg/xTQf4KipD5L0W1k3r5BxSENUhPBlRVU/UVUtOWSK6xFZLdK7yrFjN9AA "Retina 0.8.2 – Try It Online") Link includes test cases. Edit: Saved 1 byte thanks to @Grimmy. Explanation:
```
.{4}
$& 
```
Group the nibbles.
```
(.+) 
[$1]
```
Bracket the nibbles.
```
T`d`L`.*]
```
Change the bits used by the nibbles from `01` to `AB` to distinguish them from the spare bits.
```
B
AB
+`BA
ABB
```
Convert from binary to unary.
```
A+(B*)
$.1
```
Convert from unary to decimal.
```
T`d`L`1\d(?=.*])
B(.)
$1
```
Convert `10-15` from decimal to hexadecimal.
```
T` `_`\w..
```
Group pairs of nibbles into bytes.
```
(\[.{18})...+]
$1..]
```
Truncate the output if there are more than 14 nibbles.
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), ~~129~~ ~~124~~ 113 bytes
-5 thanks @tsh
11 more thanks @Arnauld
```
s=>'['+s.replace(/..../g,(x,i)=>(i<56?"9ABCDEF."[x=!s[59]|i<48?"0b"+x-9:7]||x+9:"")+(s[i+7]?i&4&&x-7?' ':'':']'))
```
[Try it online!](https://tio.run/##pZHfboMgFMbvfQrmhWCsFJJ2Tlc0W9e9hDGROexYTDViGi58d0eVtrvvCf/P7/tOcvjlZ66qXnZDeGq/xVSzSbEU5jBQuBddwyuB1tjE@rhCeiV9liK52z5nbvz2vv84fGI31@xJ5du4GOVu85K55MsNdBgnUTGOOogT1/UDpHIZREUmvY3n6TDKIIAJNKOAvj@deQ8GoYY9V0IBBkpCCXWICepQOl8uK6H0fjDvZEb@hTMnLvyVIstOrJbegBmh1sjOC2CzVrToZtK63S3pYrtApvYD2ocKU1Ji1TVyKJ3y1bm1Eddtf@DVD9KApaBqT6ptBG7ao/lFUCPtm77/AQ "JavaScript (Node.js) – Try It Online")
[Answer]
# [Red](http://www.red-lang.org), 208 bytes
```
func[s][r: :rejoin b: parse s[collect[any[keep[4 skip]]copy t to end]]forall
b[b/1: pick form debase/base r["0000"b/1]2 4]b: collect[foreach[x y]b[keep
r[x any[y""]]]]if b/8[clear at b 8 b/7:".."]r["["b"]"t]]
```
[Try it online!](https://tio.run/##rY5NboQwDIX3nMLyAYakGqkjjtGt5UUSjEqhgEIqldNT8zMdZtpd6yiJnvP5vUQp5xcpibOqmKuPLtDIFAsoorz1dQe@gMHFUWCk0LethESum6gRGegMY1MPzKEfJkiQepCuZK766No28@Rzq9N1aEBb71CKd6PkywGR0GihIvwEZ9aYq72y4sIrfcLEfg3KoooldUJkrboCn18otOIiuAQeLtp4LvB0QlZnQo@MiXkeYt0lqACNNRazm9Q6amsfgEUba39rKWserA51fFlZXddJs93mh7P9RlfY7jH7vkd3bjfavNaZPeEWY7eoDbr72R9c/ukz1uD8BQ "Red – Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 50 bytes
```
[≔⪪Ｓ⁴θＦ›⁴Ｌ§θ±¹≔⊟θω≔⪫⪪↥⭆θ⍘↨²ι¹⁶¦² θ⎇‹²⁰Ｌθ⁺…θ¹⁸..θ]ω
```
[Try it online!](https://tio.run/##VU/BTgMhEL37FYTTbIINbBpj4qn2YGqq2aR6Mh7IirskBFigar8eB3Zb45AZXmaG9x79KEPvpMm5C9omoG@0ubvaxKgHCwdvdIKd9cd0SDgeoGFkjTnhzqcLBB6CkkkFWDOyV3ZII2zSzn6oH5gYeVYDDkE0GGSh7JyHCRm@/1QenT5LvXqvQi@jglnvSfpCdI@dxUCB0DKikUPcIDEjLSYldLE1f@NFBSvDCfYqRmj5xd1UHnTmGGF76o3ajq4KiNvCsVr9J6Hv9ILRb84Cg5fDuSil3qUlKjiXOq2Qz1u1ma@/zC8 "Charcoal – Try It Online") Link is to verbose version of code.
```
[
```
Output the opening `[`.
```
≔⪪Ｓ⁴θ
```
Split the input into nibbles.
```
Ｆ›⁴Ｌ§θ±¹≔⊟θω
```
Save the last slice if it's not a whole nibble.
```
≔⪫⪪↥⭆θ⍘↨²ι¹⁶¦² θ
```
Convert each nibble into uppercase base 16, joining with alternate spaces.
```
⎇‹²⁰Ｌθ⁺…θ¹⁸..θ
```
If the resulting string is greater than 20 characters then truncate it to 18 and add `..` otherwise output the string.
```
]
```
Output the closing `]`.
```
ω
```
Output any left-over bits.
[Answer]
# [Perl 5](https://www.perl.org/) (`-p`), ~~91~~, 89 bytes
-2 bytes thanks to Xcali++
```
s/.{4}/sprintf"%X",oct"0b$&"/eg;$\=$';s/$\$//;s-.{12}\K...+-..-;s-..(?=.)-$& -g;$_="[$_]"
```
[Try it online!](https://tio.run/##pY3dCsIwDIXv9xRS6qZo00T0agwfwBcQnAyUKQPZxrq7sVe39k/n/QJp0uQ7J23ZvQ6a51mSpFpJGPajVG1X1f2DLc9s29x7hjceM1k@U4PxJFWS51zKVAkYaDfmJwDYCABhJ7A6ZrAWPF4IwxcZu/DiyrRGQorQBEVE7mNfJJoaM0eH/EXkFpb/UugrBi39AIdQMAppgbANIq9zZHCbLMnbesjcnqGddZjw3bR91dRKi/YD "Perl 5 – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 50 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
ò4
jJUÌÊ¦4
®n2G uÃò mq
"[]"i1WjT7 ¸h18WÊ?"..":P)+V
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=8jQKakpVzMqmNAqubjJHIHXD8iBtcQoiW10iaTFXalQ3ILhoMThXyj8iLi4iOlApK1Y&input=WyIwMTAxIiwKICIwMDAwMSIsCiAiMTEwMTAxIiwKICIxMDEwMDExMSIsCiAiMTAxMDAxMTExMTAwIiwKICIwMDAwMDAwMDAwMDAwMDAiLAogIjAxMTExMDEwMTEwMTAwMTExMDAxMDAxMTAwMDExMSIsCiAiMTEwMTExMTAxMDEwMTEwMTEwMTExMTEwMTExMDExMTEiLAogIjExMTEwMTAxMDAwMTEwMDAwMDAxMTExMDExMDAxMTEwMDExMTAwMTAwMTEwMTExMDAwMTAwMDAwMTAwIiwKICIxMTExMDEwMTAwMDExMDAwMDAwMTExMTAxMTAwMTExMDAxMTEwMDEwMDExMDExMTAwMDEwMDAwMDEwMDEiLAogIjExMTEwMTAxMDAwMTEwMDAwMDAxMTExMDExMDAxMTEwMDExMTAwMTAwMTEwMTExMDAwMTAwMDAwMTAwMTAiXQotbQpbNV0KWzBdMQpbRF0wMQpbQTddCltBNyBDXQpbMDAgMF0wMDAKWzdBIEQzIDkzIDFdMTEKW0RFIEFEIEJFIEVGXQpbRjUgMTggMUUgQ0UgNzIgNkUgMjBdMTAwCltGNSAxOCAxRSBDRSA3MiA2RSAuLl0KW0Y1IDE4IDFFIENFIDcyIDZFIC4uXTA)
```
ò4            (Input as a string) partitioned on each 4 bits.
jJ             V = get n elements from last index and remove them
  UÌÊ¦4        n = is last element length != 4 ?
®n2G uÃò mq           Convert each nibble to base 16,
     uÃ        to uppercase,
       ò mq    and join each pair.
"[]"i1         Inserts between squares :
      WjT7      first 7 elements(removing them),
           ¸    joined with space.
h18             Then replace characters at index 18 with :
   WÊ?".."       '..' if not empty
          :P     else empty string.
)+V           Finally appends remaining bits and outputs implicitly.
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~194~~ ~~181~~ ~~191~~ 190 bytes
Thanks to ceilingcat (-14 bytes) for the suggestions. Fixed an edge case (+10 bytes).
The function takes the input string and builds up byte-sized representations a nibble at a time, outputting the results until the sixth byte, and changing the `[` to a space after the first byte output (if there is one). The buffer is reset after each output.
After the sixth byte, nothing is output until the entire string is processed, but if the length exceeds 59 bytes (7 bytes + 3 bits), the stored representation changes to `..`, which is then output at the end. Excess bits that don't fit in a nibble are printed from the end of the input string. There is an edge case that I had to specifically check for, which is an input between 49 and 51 bytes (6 bytes + 3 bits), as an extra space would normally get printed before the ending bracket.
```
c,t;f(char*s){char u[4]="[";for(t=c=0;*s;c++>58?u[1]=u[2]=46:0)t+=t+*s++-48,c%4>2?u[c%8/4+1]=t+48+7*(t>9),t=0:0,c%8>6&c<48?printf(u),*(int*)u=32:0;printf("%s]%s",u+(c%8<1|c-48U<4),s---c%4);}
```
[Try it online!](https://tio.run/##pY/BcsIgEIbvPAWTThwISQuW2tSE@BQ9ZXKwaDQzGp1A2oO1j94USKztUWUG@Nn9/l1WRispu06GOimRXM@bQOGDvWGb80J4uZeUuwZpIQVNApVIQrKneNbmrBBtPi4En0wp1kRoEihCIh6H0ufZ2BDSjx84MZwmPCbPAdLZCw61oFNqmDibjGTK49m@qWpdohaHATIqwK14HE9pMsQ9XxW@8sKWIGNK2ac0PV5TjkMVRZHphZNjd1fVctMuljBVelHt7tcZ@BfaVG82BkxFuJ1XNXrfVQsMDwBCN6sZDBhtJ03gl5Lz2jbemrZwpHACy2a5RAr3DgjPX4MigwYyjEuU6KT2rVbI89zrCI4dZZQBahYDjLmHPSljZ2Hi1CF/FnAJy58o2t908LJfwCFsKDRsCwzZwdT7HDlUO5e08mKD/fSlHquvMl3bjPbnLV52k5l@y3IzX6ku@vgB "C (gcc) – Try It Online")
[Answer]
# [Burlesque](https://github.com/FMNSSun/Burlesque), 48 bytes
```
4co{L[4.<}ptl_FLjb2b62co)++sa7.>{6.+".."[+}if+]Q
```
[Try it online!](https://tio.run/##SyotykktLixN/f/fJDm/2ifaRM@mtqAkJ97NJyvJKMnMKDlfU1u7ONFcz67aTE9bSU9PKVq7NjNNOzbw/39DIDAAQQMDQxABpkFChmAGjADLgpkGEFVAEgA "Burlesque – Try It Online")
```
4co       #Split into nibbles
{L[4.<}pt #Partition into those whose lengths >4 and those <4
l_FL      #Take the remainder as a flat list
jb2b6     #Convert the main block into base 16 (via binary)
2co)++    #Join as pairs
sa7.>     #Length greater than 7
{
 6.+      #Take first 6 discarding remainder
 ".."[+   #Append ".."
}if       #If length > 6
+]        #Append remainder bits
Q         #Prettify
```
]