原创 bc: convert base for numbers in linux

2009-6-22 15:39 2774 4 4 分类: FPGA/CPLD
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


PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
4
关闭 站长推荐上一条 /3 下一条