Skip to main content
shorter answer
Source Link
Natte
  • 1.1k
  • 5
  • 9

sed 4.2.2, -E 178178 141 bytes

s/./:&FEDCBA9876543210:/g
:
s/:(.).([^:]*\1\w)\w*\1/:\1\2/g
t
s/[^:]\w/ /g
s/:../:/g
s/ +/&&&&/
s/ +/&&&&/
s/://g
s/$/:/
:b
s/^(.+)\1:/\1: /
s/^ (.*)\1:/\1:X/
tbt
s/://g
:z
s/^.{,7}$/ &/
tz

Try it online!

Takes newline-separated input

-35 thanks to DLosc

Explanation

s/./:&FEDCBA9876543210:/g  add hex digits to each input char
:                         do
s/:(.).([^:]*\1\w)\w*\1/:\1\2/g  remove one hex digit if it isn't the input char
t                   find index of input char in whilehex ^^string
s/[^:]\w/ /g                
s/:../:/g                 left is 2 strings which lengths corresponds to the input
s/ +/&&&&/
s/ +/&&&&/                multiply first strings' length by 16
s/://g                     add the 2 strings, left is a unary number
:
s/$/^(.+)\1:/
 \1:b              /          convert to base 2, one bit at a time
s/^(.+)\1:/\1: /
s/^ (.*)\1:/\1:X/
tbt
s/://g
:z
s/^.{,7}$/ &/             pad with spaces until length > 7
tz

sed 4.2.2, -E 178 bytes

s/./:&FEDCBA9876543210/g
:
s/:(.).([^:]*\1)/:\1\2/g
t
s/[^:]/ /g
s/:../:/g
s/ +/&&&&/
s/ +/&&&&/
s/://g
s/$/:/
:b
s/^(.+)\1:/\1: /
s/^ (.*)\1:/\1:X/
tb
s/://g
:z
s/^.{,7}$/ &/
tz

Try it online!

Takes newline-separated input

Explanation

s/./:&FEDCBA9876543210/g  add hex digits to each input char
:                         do
s/:(.).([^:]*\1)/:\1\2/g  remove one hex digit if it isn't the input char
t                         while ^^
s/[^:]/ /g                
s/:../:/g                 left is 2 strings which lengths corresponds to the input
s/ +/&&&&/
s/ +/&&&&/                multiply first strings' length by 16
s/://g                    add the 2 strings, left is a unary number
s/$/:/
 :b                        convert to base 2, one bit at a time
s/^(.+)\1:/\1: /
s/^ (.*)\1:/\1:X/
tb
s/://g
:z
s/^.{,7}$/ &/             pad with spaces until length > 7
tz

sed 4.2.2, -E 178 141 bytes

s/./&FEDCBA9876543210:/g
s/(\w)\w*\1//g
s/\w/ /g
s/ +/&&&&/
s/ +/&&&&/
s/://
:
s/^(.+)\1:/\1: /
s/^ (.*)\1:/\1:X/
t
s/://
:z
s/^.{,7}$/ &/
tz

Takes newline-separated input

-35 thanks to DLosc

Explanation

s/./&FEDCBA9876543210:/g  add hex digits to each input char
s/(\w)\w*\1//g            find index of input char in hex string
s/\w/ /g                  left is 2 strings which lengths corresponds to the input
s/ +/&&&&/
s/ +/&&&&/                multiply first strings' length by 16
s/://                     add the 2 strings, left is a unary number
:
s/^(.+)\1:/\1: /          convert to base 2, one bit at a time
s/^ (.*)\1:/\1:X/
t
s/://
:z
s/^.{,7}$/ &/             pad with spaces until length > 7
tz
Source Link
Natte
  • 1.1k
  • 5
  • 9

sed 4.2.2, -E 178 bytes

s/./:&FEDCBA9876543210/g
:
s/:(.).([^:]*\1)/:\1\2/g
t
s/[^:]/ /g
s/:../:/g
s/ +/&&&&/
s/ +/&&&&/
s/://g
s/$/:/
:b
s/^(.+)\1:/\1: /
s/^ (.*)\1:/\1:X/
tb
s/://g
:z
s/^.{,7}$/ &/
tz

Try it online!

Takes newline-separated input

Explanation

s/./:&FEDCBA9876543210/g  add hex digits to each input char
:                         do
s/:(.).([^:]*\1)/:\1\2/g  remove one hex digit if it isn't the input char
t                         while ^^
s/[^:]/ /g                
s/:../:/g                 left is 2 strings which lengths corresponds to the input
s/ +/&&&&/
s/ +/&&&&/                multiply first strings' length by 16
s/://g                    add the 2 strings, left is a unary number
s/$/:/
:b                        convert to base 2, one bit at a time
s/^(.+)\1:/\1: /
s/^ (.*)\1:/\1:X/
tb
s/://g
:z
s/^.{,7}$/ &/             pad with spaces until length > 7
tz