Printf notes: Difference between revisions
From Federal Burro of Information
Jump to navigationJump to search
(Created page with " hex: <pre> mitsor-bpe01:/etc # printf "%.8x\n" 13 0000000d mitsor-bpe01:/etc # printf "%.8x\n" 14 0000000e mitsor-bpe01:/etc # printf "%.8x\n" 15 0000000f mitsor-bpe01:/etc ...") |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 13: | Line 13: | ||
mitsor-bpe01:/etc # | mitsor-bpe01:/etc # | ||
</pre> | </pre> | ||
binary with bc: (printf can't do this) | |||
<pre> | |||
#NOTE: Using bc command you can directly get output at command line. | |||
# $ echo 'obase=2;15' | bc | |||
# 1111 | |||
# $ echo 'obase=2;1023' | bc | |||
# 1111111111 | |||
# $ echo 'obase=2;1024' | bc | |||
# 10000000000 | |||
# No need of ibase=10, because default ibase is 10. | |||
</pre> | |||
== Also see == | == Also see == |
Latest revision as of 16:14, 10 May 2013
hex:
mitsor-bpe01:/etc # printf "%.8x\n" 13 0000000d mitsor-bpe01:/etc # printf "%.8x\n" 14 0000000e mitsor-bpe01:/etc # printf "%.8x\n" 15 0000000f mitsor-bpe01:/etc # printf "%.8x\n" 16 00000010 mitsor-bpe01:/etc #
binary with bc: (printf can't do this)
#NOTE: Using bc command you can directly get output at command line. # $ echo 'obase=2;15' | bc # 1111 # $ echo 'obase=2;1023' | bc # 1111111111 # $ echo 'obase=2;1024' | bc # 10000000000 # No need of ibase=10, because default ibase is 10.