Jump to content

Boolean expressions

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
11 replies to this topic

#1
Sionofdarkness

Sionofdarkness

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 384 posts
Boolean expressions are stuff like 5>8 and stuff of the like, correct? I'm pretty sure that they're used a lot in loops, but are they used in any other functions?

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
A boolean expression is an expression that evaluates to True or False. They are primarily used in loop tests and if statements.

In C++, you also have bitwise logical operators that treat 1 as True and 0 as False. By using these operators on unsigned char, you can easily do things like IP masking. Boolean expressions also show up a LOT in electronics, in things called logic gates. Those are what actually make all of our computers work.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
icepack

icepack

    Programmer

  • Members
  • PipPipPipPip
  • 115 posts
loops and if statements are conditional
the condition is a boolean statement

so 5>8 would evaluate false

and false is, of course, a boolean value
some programming languages allow either true/false or 1/0

#4
Sionofdarkness

Sionofdarkness

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 384 posts
Oh yeah, now it's all coming back to me, I used to know some stuff about this but I'd forgotten. What's the thing called with the AND/OR/XOR stuff?

#5
icepack

icepack

    Programmer

  • Members
  • PipPipPipPip
  • 115 posts
logic...?

#6
Guest_NeedHelp_*

Guest_NeedHelp_*
  • Guests
They are used in conditional statements like 5>x OR x>10

#7
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
AND returns true only if both operands are true.
OR returns true if at least one operand is true.
XOR returns true if the operands are different.
NOT returns the opposite of its operand.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#8
brackett

brackett

    Programmer

  • Members
  • PipPipPipPip
  • 192 posts
XOR returns FALSE if both operands are 0. XOR is basically, "if one or the other, but not both".

#9
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
1 Xor 1 = 0
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#10
Guest_Kaabi_*

Guest_Kaabi_*
  • Guests
Oh! XOR is basically the exclusive or, and the regular OR is the inclusive OR, I learned that back in geometry. Interesting...

#11
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Exactly.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#12
DevilsCharm

DevilsCharm

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 884 posts
That XOR thing makes sense, because XOR is the inclusive, and X is a symbol for deleting something, so it deletes the AND and makes it inclusive... I know that's a bit convoluted (I like using that word), but you know what I mean.