\$\begingroup\$@facepalm42 To avoid facepalms, I strongly recommend using the Sandbox to help you design future challenges before posting them.\$\endgroup\$
– AdámJul 9 '19 at 10:13

2

\$\begingroup\$How is it possible to display all byte values at once, if it won't fit on the screen? Scrolling clearly isn't "at once". Also, what's wrong with (a function) just returning the values?\$\endgroup\$
– AdámJul 9 '19 at 10:16

7

\$\begingroup\$@facepalm42 Please don't change the spec so long time after posting the challenge. The original post didn't specify the exact format of the hexadecimal numbers, leaving it up to the answerers. Your latest edit invalidated my existing answer!\$\endgroup\$
– AdámJul 9 '19 at 10:31

11

\$\begingroup\$Is there a particular reason you only allow command-line argument or a user prompt? What's wrong with e.g. taking the file name as a function argument?\$\endgroup\$
– AdámJul 9 '19 at 10:40

3

\$\begingroup\$It would be helpful if you had a simple hello.txt text file as an example as an input and what the expected output should be. For instance, if the hello.txt contained simply the word hello with a line break, how would this be expressed in the output? Are you grouping the bytes in 16-bit,32-bit or 64-bit words? Or is each byte expressed as two-digit hex? Are spaces acceptable after each byte as hex, or after each x-bit word? Do you require an 0x pre-fix for each byte?\$\endgroup\$
– Shaun BebbersJul 9 '19 at 10:49

\$\begingroup\$Does this read the contents of a file given a file-path as program argument? Based on the TIO it seems to just read from STDIN, but I don't know Ruby well-enough to say it's incorrect.\$\endgroup\$
– Kevin CruijssenJul 10 '19 at 18:33

1

\$\begingroup\$@KevinCruijssen Yes, it takes the file path(s) as program argument. If there are no arguments, $< switches to reading from STDIN instead.\$\endgroup\$
– Value InkJul 13 '19 at 1:14

Java 11, 156 154 bytes

Try it online by using ./.input.tio as argument file-path, which will have a given input as file-content.

Explanation:

import java.nio.file.*; // Required import for Files and Paths
interface M{ // Class
static void main(String[]a) // Mandatory main method
throws Exception{ // With mandatory thrown clause for the readAllBytes builtin
a[0] // Get the first argument
Path.of( ) // Get the file using that argument as path
Files.readAllBytes( ) // Get all bytes from this file
for(int b: ) // Loop over each of them:
System.out.printf( // And print the current byte
"%02X ",b);}} // As uppercase hexadecimal with leading 0
// and trailing space as delimiter

\$\begingroup\$Should be able to drop the trailing ?> and save 2 bytes, or if that doesn't work then replace ?> with a semicolon and save 1 byte.\$\endgroup\$
– manassehkatz-Moving 2 CodidactJul 10 '19 at 4:34

Anonymous tacit prefix function. Returns (and implicitly prints, if the value isn't otherwise consumed) a two-row matrix with the top 4 bits represented as a decimal number 0–15 in the top row and the bottom 4 bits similarly represented in the bottom row. That is, the matrix has as many columns as the file has bytes.

Python 3, 59 bytes

This is pretty straightforward; it opens a filename given as input on STDIN, reads it, converts each character to its ASCII value, converts each number to hex, strips off the "0x" that precedes hexademical values in Python, pads the value with a zero if necessary, then joins the values together with spaces.

TIO has 3 arg in the last line because TIO passes "-e bye" to the command line parser before passing in the code

Code Explanation

: f \ start a function definition
slurp-file \ open the file indicated by the string on top of the stack,
\ then put its contents in a new string on top of the stack
hex \ set the interpreter to base 16
0 do \ loop from 0 to file-length - 1 (inclusive)
dup c@ \ get the character value from the address on top of the stack
0 <# # # #> \ convert to a double-length number then convert to a string of length 2
type \ output the created string
space \ output a space
1+ \ add 1 to the current address value
loop \ end the loop
; \ end the word definition
1 arg f \ get the filename from the first command-line argument and call the function

The code is quite self-explanatory because of the long command names. It should be read mostly from right to left:

$ScriptCommandLine is a list of {scriptname, commandlinearg1, commandlinearg2, ...}
Last@... extracts the last command-line argument
BinaryReadList@... reads the named file into a list of bytes
IntegerString[...,16,2] converts each byte to a 2-digit hex string (lowercase)
StringRiffle@... converts this list of strings into a single string with spaces
ToUpperCase@... converts the string to uppercase
Print@... prints the result to stdout

Your Answer

If this is an answer to a challenge…

…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.

…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.

…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.

More generally…

…Please make sure to answer the question and provide sufficient detail.

…Avoid asking for help, clarification or responding to other answers (use comments instead).

Code Golf Stack Exchange is a site for recreational programming competitions, not general programming questions. Challenges must have an objective scoring criterion, and it is highly recommended to first post proposed challenges in the Sandbox.