I need to return the first 16 bytes of a binary file as hexadecimal string. Is there a better way to do it than this?
(byte 0 of it as hexadecimal & byte 1 of it as hexadecimal & ... & byte 15 of it as hexadecimal) of file "/path/to/file.bin"
Away from a debugger now but probably something along the lines of
Concatenation of (bytes (integers in (0,15)) of it as hexadecimal as string) of file “whatever”
Hm maybe need to pad it as well?
concatenation of (last 2 of ("0" & it) )of (bytes (integers in (0,15)) of it as hexadecimal as string)of file "whatever"
@JasonWalker apparently needs no debugger .
as hexadecimal
returns a string, so the only thing “wrong” was the redundant as string
. This worked great:
concatenation of (bytes (integers in (0,15)) of it as hexadecimal) of file "/path/to/file.bin"
Thanks, Jason!
Glad to hear it. In case you saw the notification on email vs here in the group, I did edit it because I’m not sure whether “as hexadecimal” pads the results, ie. you may need to pad it to get “0a” instead of “a” for decimal value 10.
Is the padding needed or no?
Oddly, none of the particular bytes I’m reading have a leading zero when converted to hexadecimal strings, so I don’t rightly know.
I think the padding is required.
q: ((integers in (0, 5); integers in (13, 20)) as hexadecimal)
A: 0
A: 1
A: 2
A: 3
A: 4
A: 5
A: d
A: e
A: f
A: 10
A: 11
A: 12
A: 13
A: 14
T: 0.087 ms
I: plural string
q: lasts 2 of (("0" & it) of ((integers in (0, 5); integers in (13, 20)) as hexadecimal))
A: 00
A: 01
A: 02
A: 03
A: 04
A: 05
A: 0d
A: 0e
A: 0f
A: 10
A: 11
A: 12
A: 13
A: 14
T: 0.230 ms
I: plural substring
q: concatenation of lasts 2 of (("0" & it) of ((integers in (0, 5); integers in (13, 20)) as hexadecimal))
A: 0001020304050d0e0f1011121314
T: 0.328 ms
I: singular string