Hex Dump your Source Code
Perl, 81 bytes
#!perl -l
$_=q($%+=print"00$%0: @{[unpack'(H2)*']} $_"for"\$_=q($_);eval"=~/.{16}/g);eval
Counting the shebang as one. Having the code length be a multiple of 16 saves quite a bit on formatting. Using eval
to reassign $_
to itself borrowed from ais523.
Output:
0000: 24 5f 3d 71 28 24 25 2b 3d 70 72 69 6e 74 22 30 $_=q($%+=print"0
0010: 30 24 25 30 3a 20 40 7b 5b 75 6e 70 61 63 6b 27 0$%0: @{[unpack'
0020: 28 48 32 29 2a 27 5d 7d 20 20 24 5f 22 66 6f 72 (H2)*']} $_"for
0030: 22 5c 24 5f 3d 71 28 24 5f 29 3b 65 76 61 6c 22 "\$_=q($_);eval"
0040: 3d 7e 2f 2e 7b 31 36 7d 2f 67 29 3b 65 76 61 6c =~/.{16}/g);eval
Try it online!
Perl + xxd + cut, 61 bytes
$_=q(open F,"|xxd -g1|cut -c5-";print F"\$_=q($_);eval");eval
Try it online!
This is a universal quine constructor in Perl + a call to xxd
and cut
to do the hexdumping. None of the programs in question have a builtin to do a hexdump in the format in the question; however, xxd -g1
comes very close and so it's possible to use cut
to trim the output into the correct shape.
The universal quine constructor is $_=q("\$_=q($_);eval");eval
, which creates a copy of its own source code in memory, and can be modified to perform arbitrary operations on it. In this case, I use open "|"
and print
to pipe the input into external programs, xxd
which does the bulk of the hexdumping work and cut
which changes it into the required format.
JavaScript (ES6) 229 219 162 bytes
Thanks to @Neil for saving a lot of bytes
Note
Quite a few people think accessing the source code of a function the way I do it is cheating, but according to @Dennis, it's fine. As such, I'll leave my answer here.
Code
f=_=>([...c=`f=`+f].map(d=>d.charCodeAt()[t=`toString`](16)).join` `+` `.repeat(46)).match(/.{48}/g).map((s,i)=>`00${i[t](16)}0: `+s+c.substr(i*16,16)).join`\n`
Usage
f()
Simply call the function with no arguments.
Output
0000: 66 3d 5f 3d 3e 28 5b 2e 2e 2e 63 3d 60 66 3d 60 f=_=>([...c=`f=`
0010: 2b 66 5d 2e 6d 61 70 28 63 3d 3e 63 2e 63 68 61 +f].map(c=>c.cha
0020: 72 43 6f 64 65 41 74 28 29 5b 74 3d 60 74 6f 53 rCodeAt()[t=`toS
0030: 74 72 69 6e 67 60 5d 28 31 36 29 29 2e 6a 6f 69 tring`](16)).joi
0040: 6e 60 20 60 2b 60 20 60 2e 72 65 70 65 61 74 28 n` `+` `.repeat(
0050: 34 36 29 29 2e 6d 61 74 63 68 28 2f 2e 7b 34 38 46)).match(/.{48
0060: 7d 2f 67 29 2e 6d 61 70 28 28 73 2c 69 29 3d 3e }/g).map((s,i)=>
0070: 60 30 30 24 7b 69 5b 74 5d 28 31 36 29 7d 30 3a `00${i[t](16)}0:
0080: 20 60 2b 73 2b 63 2e 73 75 62 73 74 72 28 69 2a `+s+c.substr(i*
0090: 31 36 2c 31 36 29 29 2e 6a 6f 69 6e 60 5c 6e 60 16,16)).join`\n`