Advanced math Tools BC: decimal precision, binary conversion, square and square root calculation

Source: Internet
Author: User
Tags ibase


BC is an advanced tool for mathematical operations and contains a number of options for performing floating-point arithmetic and applying some advanced functions:

[Email protected] ~]# echo 3*2.12 | Bc6.36[[email protected] ~]# n=54[[email protected] ~]# m= ' echo ' $n *1.5 ' | BC ' [[email protected] ~]# echo $m 81.0[[email protected] ~]#


The other second-generation parameters can be placed in front of the specific operation to be performed, with a semicolon as the delimiter, passed to the BC by a pipe character.


Set Decimal precision:

Scale can set the number of digits after the decimal point. scale=2 is two digits after the decimal point is reserved.

[Email protected] ~]# echo "SCALE=2;17/8" | bc2.12

Binary conversions:

IBase is the number of inputs, and obase is the number of outputs. ( you can omit ibase when the input is decimal)

[[email protected] ~]# echo "obase=2; $no" |bc1010[[email protected] ~]# no=100[[email protected] ~]# echo "obase=2; $no" |b C1100100[[email protected] ~]# no=1100100[[email protected] ~]# echo "obase=10;ibase=2; $no" | bc100


Calculate squared and square roots:

[Email protected] ~]# echo "sqrt (9)" | BC//square root (square root) 3[[email protected] ~]# echo "4^2" | BC//square (SQ) 16



Advanced math Tools BC: decimal precision, binary conversion, square and square root calculation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.