$ bc
BC> ibase=2
BC> 110&101 // wanna get 100
(standar_in) 8: syntax error
Wikipedia informs that the ops are "|, & and ^". It may be that they work only in certain BC-types or I misread some开发者_运维百科thing.
Those operators are listed in the section 'Missing' operators relative to C, which ends with "... are not available in POSIX bc"
Despite bc won't do it, you can use arithmetic expansion directly on the terminal if you use bash.
To XOR 44 and 61, you can do:
echo $((44^61))
If you want to use binary code, then:
echo $((2#110^2#101))
See Numerical Constants for changing the base.
See bitwise operators section to peep at available operators.
The wikipedia article is pretty clear that these ops aren't in either POSIX bc or gnu bc. The man page has no mention of them either.
精彩评论