Let us say there is a variable in bash script with value "001" how can i write this binary data into a file as bits (as "001" not "1") echo writes it as string but i want to write in bits.
相关问题
- How to get the return code of a shell script in lu
- JQ: Select when attribute value exists in a bash a
- Invoking Mirth Connect CLI with Powershell script
- Emacs shell: save commit message
- bash print whole line after splitting line with if
相关文章
- 使用2台跳板机的情况下如何使用scp传文件
- In IntelliJ IDEA, how can I create a key binding t
- Check if directory exists on remote machine with s
- shell中反引号 `` 赋值变量问题
- How get the time in milliseconds in FreeBSD?
- Reverse four length of letters with sed in unix
- Launch interactive SSH bash session from PHP
- BASH: Basic if then and variable assignment
Most often you want to write a pattern (for instance a 32 bit pattern).
Another example:
You can write arbitrary bytes in hex or octal with:
If you have binary, it's a bit tricker, but you can turn it into octal with:
which of course can be nested in the above:
Note that this only works with up to 8 bits. If you want to write longer values, you have to split it up into groups of 8.
Using bc (in CentOS 7.4):
RESULT: 111111
If leading zeros are needed then:
RESULT: 0000000000111111
Note the use of 16 in the printf format; change value to limit leading-zero count
Just use the
%b
in the printf:so, above both prints binary value for the decimal
10
.output
you can even mix
A couple of more general functions to output integers to a file: