A bitcoin "brainwallet" is a secret passphrase you carry in your brain.

The Bitcoin Brainwallet Private Key Base58 Encoder is the third of three functions needed to calculate a bitcoin PRIVATE key from your "brainwallet" passphrase.

This base58 encoder uses the obase parameter of the amazing bc utility to convert from ASCII-hex to base58. Tech note: bc inserts line continuation backslashes, but the "read s" command automatically strips them out.

I hope that one day base58 will, like base64, be added to the amazing openssl utility.

by David Winterbottom (codeinthehole.com)

]]>Same functionality without using bash functions.

by David Winterbottom (codeinthehole.com)

]]>The "proportional set size" is probably the closest representation of how much active memory a process is using in the Linux virtual memory stack. This number should also closely represent the %mem found in ps(1), htop(1), and other utilities.

by David Winterbottom (codeinthehole.com)

]]>POSIX compliant arithmetic evaluation.

= 10*2+3

by David Winterbottom (codeinthehole.com)

]]>Use the standard calculator bc to convert decimals to hex

by David Winterbottom (codeinthehole.com)

]]>Calculate pi from the infinite series 4/1 - 4/3 + 4/5 - 4/7 + ...

This expansion was formulated by Gottfried Leibniz: http://en.wikipedia.org/wiki/Leibniz_formula_for_pi

I helped rubenmoran create the sum of a sequence of numbers and he replied with a command for the sequence: 1 + 2 -3 + 4 ...

This set me thinking. Transcendental numbers!

seq provides the odd numbers 1, 3, 5

sed turns them into 4/1 4/3 4/5

paste inserts - and +

bc -l does the calculation

Note: 100 million iterations takes quite a while. 1 billion and I run out of memory.

by David Winterbottom (codeinthehole.com)

]]>by David Winterbottom (codeinthehole.com)

]]>If you want a sequence that can be plotted, do:

seq 8 | awk '{print "e(" $0 ")" }' | bc -l | awk '{print NR " " $0}'

Other bc functions include s (sine), c (cosine), l (log) and j (bessel). See the man page for details.

by David Winterbottom (codeinthehole.com)

]]>Exactly the same number of characters, exactly the same results, but with bc

by David Winterbottom (codeinthehole.com)

]]>To do hex to binary: echo 'ibase=16; obase=2; 16*16' | bc # prints: 111100100

To do 16*16 from decimal to hex: echo 'ibase=10; obase=16; 16*16' | bc # prints: 100

You get the idea... Alternatively, run bc in interactive mode (see man page)

by David Winterbottom (codeinthehole.com)

]]>by David Winterbottom (codeinthehole.com)

]]>by David Winterbottom (codeinthehole.com)

]]>using bc is for sissies. dc is much better :-D

Polish notation will rule the world...

by David Winterbottom (codeinthehole.com)

]]>-l auto-selects many more digits (but you can round/truncate in your head, right) plus it loads a few math functions like sin().

by David Winterbottom (codeinthehole.com)

]]>allows you to use floating point operations in shell scripts

by David Winterbottom (codeinthehole.com)

]]>When you've got a list of numbers each on its row, the ECHO command puts them on a simple line, separated by space. You can then substitute the spaces with an operator. Finally, pipe it to the BC program.

by David Winterbottom (codeinthehole.com)

]]>defines a handy function for quick calculations from cli.

once defined:

`? 10*2+3`

by David Winterbottom (codeinthehole.com)

]]>Easily convert numbers to their representations in different bases. Passing

"ibase=16; obase=8; F2A"

to bc will convert F2A (3882 in decimal) from Hex to Octal, and so on.

by David Winterbottom (codeinthehole.com)

]]>Useful for quick calculations at the command line. $math_expr is any arithmetic expression (see sample output):

4.5*16+3^2

s(3.1415926/2)

More options in the bc man page.

by David Winterbottom (codeinthehole.com)

]]>