1

I am currently reading Hacker's Delight and would like to practice as I read through the book.

Is there any command line *nix tool to perform binary operations and see output in binary?

1 Answer 1

2

I don't know about a commandline utility, but if you fire up Python in interactive mode you can define integers as bit patterns by preceeding them with 0b and print them as binary using bin():

$ ./python
Python 2.7.8 (default, Jul 17 2014, 08:49:22) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> bin(0b0101 | 0b0111) # or
'0b111'
>>> bin(0b0101 & 0b0111) # and
'0b101'
>>> bin(0b0101 ^ 0b0111) # xor
'0b10'

( # starts an end-of-line comment ).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .