Calculate from the command line with Spigot

Slashdot it! Delicious Share on Facebook Tweet! Digg!

Conversion

Spigot supports conversion between numbering systems using various kinds of syntax. The command shown here will work in every case:

echo <valueI> | spigot -b<output_base> ,base
<input_base>fd:0'

Figure 4 shows common usage examples.

Figure 4: You can convert numbers using Spigot in several different ways.

Calculating Frequency

The example from Listing 2 shows how to deal with variables as exponents. Here you see that the variables are isolated by quotes; the e-12 describes the exponent's remainder. Use the script to calculate the frequency of a resonant circuit using the coil (Inductance , ?H ) and the capacitor (Capacitor , pF ). See Figure 5 for the script's output.

Listing 2

qrgcalc.sh

#!/bin/bash
# qrgcalc.sh
echo "Resonant circuit calculation, result in MHz"
read -p "Inductance in ?H: " L
read -p "Capacitor in pF: " C
echo "Inductance: $L ?H, Capacitor $C pF"
# In the header, correct conversion for ISO units to H and F
echo "------------------------------"
qrg=$(spigot --rn -d50 "$L"e-6*"$C"e-12 | spigot --rn -d50 '(1/(2pi*sqrt(base10fd:0))/1000000)' --printf %10.3f)
echo "Frequency $qrg MHz"
Figure 5: Spigot helps calculate the frequency of a resonant circuit.

Buy this article as PDF

Express-Checkout as PDF

Pages: 4

Price $0.99
(incl. VAT)

Buy Ubuntu User

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content