Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Sam Johnson   on Mar 24 In Java Category.

  
Question Answered By: Cambria Lopez   on Mar 24

You got me intrigued and I did a scan through my C++ code  to see how often I
used bit-wise operators. Effectively never!

The only instances I turned up were where I was selecting specific options to
pass in operating system calls. E.g. in the _chmod call, you specify readable,
writeable, etc, as a series of bits in an integer parameter. Even then, all I'm
using is the "or" operator to allow me to combine the options. The options are
defined elsewhere as constants 1, 2, 4, 8 etc to allow the individual bits to be
set. Presumably the operating system routine is then using the "and" operator
to check whether individual options are set.

I didn't find any use of the exclusive-or bit-wise operator at all.

One area in which bit-wise exclusive-or is (or was) used is for overlaying
moving items on top of backgrounds on screens. The reason for this is that you
put it on with "a = a xor b" and you take it off with "a = a xor b" - i.e. you
don't need to back-up the original contents anywhere. The exclusive-or is also
used at other hardware levels - e.g. a parity bit is a single-bit exclusive-or
of all the other bits; simple magnetic tape longitudinal
cyclic-redundancy-checks (CRC's) are an exclusive-or of all the other frames in
the record.

Share: