I would like to create a file that just contains a binary number. I think that touch
can be used to create an empty file, but is there any way I can fill it with a binary number e.g. 10
(ten)? And how can I validate that the file contains the binary value of ten?
2
5
Convert the number to hex (in this case A
) and then do:
echo -en '\xA' > file
-
Thanks, however, now I don't know how I can validate this anser. E.g could I write the number 65 and in some way print that with a command? – Jonas Oct 24 '10 at 15:41
-
1
-
Thanks for
hexdump
. I added that to my question. However I don't think echoing the hexnumber is working. When I look at the file withhexdump file
I get0000000 785c 0041 0000003
and I get a different value forecho -n '\xa
> file` – Jonas Oct 24 '10 at 15:55 -
The file seems to contain something more than a number, and with
hexdump
should the hexvalue\xA
be shown asA
ora
? But it doesn't in this case. – Jonas Oct 24 '10 at 15:58 -
1@Jonas: Ok, my bad. I tested this in
zsh
and apparently zsh'secho
behaves differently than bash's. In bash you need the-e
option to echo for\x
to work. – sepp2k Oct 24 '10 at 16:01