It is currently March 29th, 2024, 1:10 am

Difference between Logical Operators and Bitwise Operators?

Get help with creating, editing & fixing problems with skins
User avatar
JpsCrazy
Posts: 667
Joined: April 18th, 2010, 2:16 pm
Location: NY, USA

Difference between Logical Operators and Bitwise Operators?

Post by JpsCrazy »

I've been learning more and more that calcs can do, well anything.

But when I get to and and or, I'm never quite sure which to use - bitwise or logical.

Basically, I don't understand the difference between & and && and | and ||.
I usually end up guessing and checking seeing what seems to work and what doesn't.
I'd love to know what's actually going on, and I'm sure I'm not the only one.

(Yes. I've googled it. But everything I find I either don't understand or I can't tell the difference between the two.)
User avatar
JamesAC
Developer
Posts: 318
Joined: July 14th, 2009, 5:57 pm

Re: Difference between Logical Operators and Bitwise Operators?

Post by JamesAC »

Generally you want to use logical operators as they are applied to the values itself, (i.e. your value could be 7). Bitwise operators look directly at the memory which stores the value, (if your actual number was 7 the the operator would look at the memory which mkes 7, i.e. 0111).

At least that is how i think it works. This site has some really good info and seems to explain the bitwise stuff quite well, i assume they would work the same in Rainmeter. http://www.learncpp.com/cpp-tutorial/38-bitwise-operators/

From reading that I think you could use bitwise and to see if a number is odd or even.

Code: Select all

Formula=(1 & #Number#) ? 1 : 2
should return 1 if the number is odd and 2 if it is even i think.
+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++
Quis custodiet ipsos custodes?
User avatar
JpsCrazy
Posts: 667
Joined: April 18th, 2010, 2:16 pm
Location: NY, USA

Re: Difference between Logical Operators and Bitwise Operators?

Post by JpsCrazy »

I really, really don't understand how 7 = 0111 in bitwise at all.
So, this is where I nod and agree and just use logical operations.

Thanks for explaining it though.
User avatar
JamesAC
Developer
Posts: 318
Joined: July 14th, 2009, 5:57 pm

Re: Difference between Logical Operators and Bitwise Operators?

Post by JamesAC »

0111 is 7 in binary, which is how numbers are stored in memory. They are converted to a more useful form when they are output.

I can certainly see why the bitwise/logical thing would be confusing and my understanding is only basic so hopefuly what i said is correct
+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++
Quis custodiet ipsos custodes?
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Difference between Logical Operators and Bitwise Operators?

Post by jsmorley »

JamesAC wrote:0111 is 7 in binary, which is how numbers are stored in memory. They are converted to a more useful form when they are output.

I can certainly see why the bitwise/logical thing would be confusing and my understanding is only basic so hopefuly what i said is correct
BitAND or BitOR? ;-)