Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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 ).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.