base#
通过修改ibase
和obase
可以实现各种进制的转化,比如十进制和二进制和十六进制之间的转换;
If you aren’t familiar with conversion between decimal, binary, and hexadecimal formats, you can
use a calculator utility such as bc or dc to convert between different radix representations. For
example, in bc, you can run the command obase=2; 240 to print the number 240 in binary
(base 2) form.
syntax#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| bc
An arbitrary precision calculator language.
More information: https://manned.org/bc.
- Start bc in interactive mode using the standard math library:
bc -l
- Calculate the result of an expression:
bc <<< "(1 + 2) * 2 ^ 2"
- Calculate the result of an expression and force the number of decimal places to 10:
bc <<< "scale=10; 5 / 3"
- Calculate the result of an expression with sine and cosine using mathlib:
bc -l <<< "s(1) + c(1)"
|