Programming facts thread

Hello, in this thread every one can share & post different programming facts, some time we find new fact that we did not realize..

I will give you and example for first post in programming facts :

#Fact : != Operator is a combination of > operator and < operator
for example (a!=b) is a combination of (a>b || a<b)


What do you think of this thread?, if it is good idea, I hope to collect hundreds of posts that has different facts so that I and every one can get benefit.


EDIT : fixed logic mistake changed (a>b && a<b ) to (a>b || a<b)
Thanks for the noticing ne555
Last edited on
That's plain wrong
a>b and a<b is a contradiction

Also, to compare equality, you may XOR and check for zero.
XOR
A B XOR
1 1 0
1 0 1
0 1 1
1 1 0

I got it thanks
Last edited on
oh my bad
I meant != is the same as less than OR greater than not and XD
took too much caffeine today
Last edited on
#Fact : Do you know there is no such thing != not equal operator,
Its just a mix of "More than && Less than" Operators in the ALU in CPU


I'm not sure where you got that "fact" from.

In x86 there's a CMP instruction which effectively performs a subtraction to compare two numbers (then discards the result).

Subtraction works because A-B will be 0 if A==B

I did not get it when using XOR for checking equality


Similar to subtraction... A ^ B will be 0 when A==B, and will be nonzero when A!=B
I wanted to say OR,
I am not in a good mode today got 0% focus ,I think it's time to stop reading and go to sleep :/

, I got OR fact from Computer Tools For Information Age, book
Last edited on
I got OR fact from Computer Tools For Information Age, book


Well either the book is making stuff up, or we aren't understanding what it means.

C++ certainly has a != operator.
The generated assembly doesn't, however the assembly doesn't have any operators so it wouldn't have ||, <, or > either.

The closest thing in the assembly to the != operator is the CMP instruction, and CMP is definitely closer to ==/!= than it is to some kind of weird OR operation.
so it's me I did the topic wrong, I am suppose to say that the not equal is not a primary condition, its a combination of of the basic conditions >,<, and ==
so from < and >
we can get the != operator,

I fixed the topic, what do you think now?
Last edited on
closed account (z05DSL3A)
Tommy Flowers (22 December 1905 – 28 October 1998) designed the world's first electronic digital computer that was at all programmable.
#Fact : != Operator is a combination of > operator and < operator
for example (a!=b) is a combination of (a>b || a<b)

That's false.
However, there's a slight chance that your book was talking about non-equivalence relationship derived from strict weak ordering, where a is not equivalent to b if a < b or b < a.
Here is what is says literally with bold too :

after it mentioned equal-to condition, less-than-condition, and grater than-condition:

In addition to these three basic conditions, the computer can test for combination of conditions: less-than-or-equal-to, greater-than-or-equal-to, and less-than-or-grater-than conditions. Note that less-than-or-grater-than is the same as not-equal-to.

Last edited on
Is he talking at the machine code level?

I don't know if I would trust this book.
It seams like the book is geared towards beginners who have never seen programming before. The book uses the same as, and the computer can, which can be misleading. The OP mistook what the book said and thought that it had something to do with the low level instructions that the computer executes. All the book really meant was that the two expressions are logically equivalent.
Yes, the book starts from 0, it start from what is a computer, how can a computer increase productivity, I like to read every single line of the book don't want to miss an information even if I know most of it.

No Disch, the topic I found this sentence on is about the Arithmetic Logic Unit in the CPU.

thank you htirwin I misunderstood it as you said.

But now thanks to the kind users, I will focus more :)
Last edited on
Topic archived. No new replies allowed.