Sometimes it can be difficult to figure out how to convert some binary quantity that you want to it's hexidecimal representation.

Quick: is 110110 0x36 or 0xd2?

It turns out that most Unix systems, including linux and the IU CS department's Burrow machines, provide a utility that makes these kinds of conversions very simple: bc.

To use bc for binary-to-hex conversion, simply call it on the command line. You will be put into the bc shell, which looks like this:

$ bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.

Your cursor will be sitting at a blank line. To quit bc, simply hit Ctrl-D, and you will be returned to the command-line.

bc, it turns out, is a powerful tool for doing all different kinds of calculations, but we're going to trivialize that power by cutting to the chase. To do numeric base conversions in bc, you simply set the special variables ibase and obase, to whatever bases you want to use. bc will do the rest.

obase is used to specify the output base for numeric representation, and ibase for input. So by setting obase to 16 and ibase to 2, you can enter binary strings and have bc output hex numbers. Similarly, you can set obase to 2 (or 10) and ibase to 16, and have bc tell you what those hex values really mean.

Some examples:

$ bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
obase=16
ibase=2
110110
36

And the other way:

$ bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
obase=10
ibase=16
3EF
1007

Note that bc expects hex input to use capital letters.