I frequently use the command-line GNU bc calculator to do quick arithmetic while debugging C programs. An ongoing annoyance is bc's insistence that the hexadecimal digits A-F must be entered in uppercase. Other software, such as GDB and printf("%p",...), output lowercase hexadecimal digits, which keeps me from cutting and pasting the values into bc. Manually typing the values can be a big time sink when I need to perform a lot of calculations.
I finally got fed up with this behavior and made a version of bc with the following modifications:
- Hexadecimal digits may now be entered in lowercase.
- Input and output defaults to base 16.
Here are links to the baseline bc source code, and the patch with my modifications:
- bc-1.06.tar.gz
(via prep.ai.mit.edu) - bc-lowercase-hex-hack.patch
tar xvfpz bc-1.06.tar.gz patch -p0 < bc-lowercase-hex-hack.patch cd bc-1.06 ./configure --with-readline make sudo mv bc/bc /usr/local/bin/xc
Update, April 22nd, 2012: The exact version of bc that works with this patch disappeared from prep.ai.mit.edu, so I'm changing the link to a locally hosted package. (This version is still available at ftp.gnu.org, for now.)
posted at 2009-09-17 11:06:50 US/Mountain
by David Simmons
tags: hexadecimal debugging bc
permalink
comments