12
$ 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 something.

otto
  • 393
  • 1
  • 4
  • 12

3 Answers3

12

Those operators are listed in the section 'Missing' operators relative to C, which ends with "... are not available in POSIX bc"

Michael Mrozek
  • 169,610
  • 28
  • 168
  • 175
6

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.

user3000327
  • 89
  • 1
  • 3
1

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.

ergosys
  • 47,835
  • 5
  • 49
  • 70