Printf notes

From Federal Burro of Information
Revision as of 16:14, 10 May 2013 by David (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

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. 


Also see