Tools
A Bash Script to Convert brainfuck Code Into C
Brainfuck is a minimalist Turing Complete language. You can read about it here.
The following bash script takes a file with brainfuck code (legal characters are >< ,.+-[] any other characters are ignored), and generates its C equivalent code, which can then be compiled with a C compiler and executed.
The output of this script lacks indentation. If you insist on having the C code indented you can achieve this by passing the output through a pipe to “indent”, “astyle” or similar programs.
The script should be called in the following way:
./bf.sh code.bf > code.c
Where code.bf is the file containing the brainfuck code.
Tiny Bash Functions to Convert Between Numeric Representations
I have these functions in my aliases file. They make it easy to convert between hex, binary and decimal representations of numbers. You might find it useful.
Just add these to your aliases file (imported from ~/.bashrc):
1 2 3 4 5 6 | function h2d { echo "obase=10; ibase=16; $( echo "$*" | sed -e 's/0x//g' -e 's/\([a-z]\)/\u\1/g' )" | bc; } function h2b { echo "obase=2; ibase=16; $( echo "$*" | sed -e 's/0x//g' -e 's/\([a-z]\)/\u\1/g' )" | bc; } function b2d { echo "obase=10; ibase=2; "$*"" | bc; } function b2h { echo "0x$(echo "obase=16; ibase=2;"$*"" | bc)"; } function d2b { echo "obase=2; ibase=10; "$*"" | bc; } function d2h { echo "0x$(echo "obase=16; ibase=10; "$*"" | bc)"; } |
Now you should be able to use it like this:
h2d 0xff
The output will be 255 in this case.
h2b is for “hex to binary”, the others are similar (h: hex, b: binary, d: decimal)
Enjoy
A Program for Bit-Slicing
I wrote this short program in C because I needed to do some bit-slicing in some homework. It's not too generic (accepts only 32 bit integers) but it can help in most cases.
An example usage of the program:
bs 0x12345678 31 4
Will give the following output:
0x12345678[31:4] = 0x1234567› Continue reading
About Me
Tags
My Twitter
Categories
- Algorithms
- Bash
- BlackBerry
- Collaboration
- Command Line
- Cool Tricks
- Easter Eggs
- Ebooks
- Firefox
- Hardware
- Humor
- Linux
- Linux Development
- Linux Kernel
- Networks
- Open Knowledge
- Other
- Productivity
- Programming
- Science
- Security
- Shell Scripts
- Short Posts
- Thoughts
- Tools
- Vim
- Web Development
- Websites
Popular Posts
Archives
- March 2010 (1)
- January 2010 (1)
- December 2009 (2)
- September 2009 (13)
- July 2009 (1)
- June 2009 (6)
- May 2009 (4)
- March 2009 (18)
- February 2009 (10)
- January 2009 (10)
- December 2008 (7)
- November 2008 (8)
- October 2008 (1)
- August 2008 (1)
- July 2008 (1)
- June 2008 (2)

Me @ Social Media