Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Bitwise Operators

  Asked By: Sam    Date: Mar 24    Category: Java    Views: 715
  

Just passed my SCJP and after spending a week learning bitwise operators I
can't help but wonder; what the heck are they used for, anyways? :-)

If I've ever had a need for them in my real life code I haven't known enough
to recognize it.

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Evelyn Hughes     Answered On: Mar 24

You are hardly needed if you are not working with
hardware level. But I will not said never because I do
think about the ad about XiLink found a clever way to
manipulate the PCB with CPU. Firmware through
interner? I need more research about this.

 
Answer #2    Answered By: Douglas Sullivan     Answered On: Mar 24

i think they're purely for that module at uni where you have to write the code
to make a calculator and then for the bonus marks you have to add funcionality
to make the >> key and the << key work when its in binary mode or whatever.

 
Answer #3    Answered By: Cambria Lopez     Answered 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.

 
Answer #4    Answered By: Topaz Ramirez     Answered On: Mar 24

I use them all the time. If I am doing something in RGB space
0xff1022 and need to work with one specific color they are handy.
If I am doing work on a PDA where space is at a premium I may store
on/off values in a single bit. Mostly and/or and shifts, but I do
use them.

 
Didn't find what you were looking for? Find more on Bitwise Operators Or get search suggestion and latest updates.




Tagged: