xxd is available on most linux distros, it just may not be installed on yours, for whatever reason. It is definitely part of the standard install AFAIK.
try
find / -type f -name xxd
xxd(1): make hexdump/do reverse - Linux man page
Duplicating what it does is not simple, IMO, because it requires a parser, endian understanding, etc. You are far better off finding it on your box, or installing it.