How to use bc to convert base of numbers in linux?
Example 1, convert decimal number, 64, to hexadecimal number. $echo "ibase=10; obase=16; 64" | bc 40
Example 2, convert hexadecimal number, 100 to decimal number. $echo "ibase=16; obase=A; 100" | bc 256
Note: The default base for both input and output is 10. The ibase is changed to be 16 in the second example. So, the obase setting is in hexadecimal number. A in this case means 10.
Example 3, convert decimal number, 1.25 to binary number. $echo "ibase=10; obase=2; 1.25" | bc 1.0100000
文章评论(0条评论)
登录后参与讨论