Most frequently used bitwise operators.
Most frequently used bitwise operators.
From your experience, what are the most frequently used bitwise operators, when not dealing with hardware?
- Kazinsal
- Member
- Posts: 559
- Joined: Wed Jul 13, 2011 7:38 pm
- Libera.chat IRC: Kazinsal
- Location: Vancouver
- Contact:
Re: Most frequently used bitwise operators.
AND and OR. Bitwise NOT is also up there. The only time I use XOR often is as a replacement for mov reg, 0.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Most frequently used bitwise operators.
Probably AND at the top. The typical OR construct has competition from a substitute writing: optionflag1+optionflag2+optionflag3
I think shifts beat bitwise NOT. Especially since they make good divides/multiplies and the compiler knows that.
I think shifts beat bitwise NOT. Especially since they make good divides/multiplies and the compiler knows that.
Re: Most frequently used bitwise operators.
BSR/BSL might be used for implementing bitmaps in e.g. memory manager in a very handy way on x86.
Learn to read.
Re: Most frequently used bitwise operators.
Uhm, probably AND, but I always use XOR when nulling something .
Re: Most frequently used bitwise operators.
signed shift when multiplying/dividing by powers of two
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
If you're new, check this out.
Re: Most frequently used bitwise operators.
OR for adding bitflags to bitfields. AND for masking and testing flagbits. XOR for toggling bitflags on and off. Left shifts for indexing arrays of various sizes (and the occasional "multiply by 2"). I use them all lots. The ones I almost never use are NOT and rotations.
Re: Most frequently used bitwise operators.
NOT is useful for reversing byte sized boolean values that most operating systems and higher level languages foolishly waste your ram with.
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
If you're new, check this out.
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: Most frequently used bitwise operators.
Depends on what the problem is. E.g.:
- For cryptography, XOR
- For bit flags and masks, AND/OR
- For array indexing, shifting
- For logic gates, NAND
- For serialization, AND/shifting (for encoding, see Combuster's point on OR)
- etc.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
Re: Most frequently used bitwise operators.
Umm... aren't all bitwise operators a type of logic gate?Love4Boobies wrote:
- For logic gates, NAND
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
If you're new, check this out.
Re: Most frequently used bitwise operators.
No.m12 wrote:Umm... aren't all bitwise operators a type of logic gate?Love4Boobies wrote:
- For logic gates, NAND
A logic gate normally refers to a circuit with one or more binary inputs and a single binary output. Clearly
13 & 5
(for example) does not fulfil these conditions. Logical operators, on the other hand, do; for example:
13 && 5
Re: Most frequently used bitwise operators.
13 & 5 performs:
You are right. It's not a logic gate - it's [in this case] 4 gates.
Code: Select all
1101
& 0101
------
0101
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
If you're new, check this out.
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: Most frequently used bitwise operators.
No. An operator is a mathematical function. For example, in the case of Boolean, there are 2^2^n operators that can be applied to an n-bit string (NAND is one of the 16 operators that can be applied on bit operand pairs and, because we are talking bitwise, we actually apply NAND to every corresponding bit pair individually). On the other hand, a logic gate is a physical device that implements a Boolean function. I hope you see the difference since it's a bit like confusing apples and arithmetic because you were taught the latter using the former.m12 wrote:Umm... aren't all bitwise operators a type of logic gate?
Also, I think you missed my point. Most of the logic gates inside digital computers are actually NAND gates, which are cheaper and sometimes slower but on top of which all other constructs can be built.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
- Owen
- Member
- Posts: 1700
- Joined: Fri Jun 13, 2008 3:21 pm
- Location: Cambridge, United Kingdom
- Contact:
Re: Most frequently used bitwise operators.
While the NAND or NOR gate can be used to construct all other logic gates... nobody actually does thisLove4Boobies wrote:Most of the logic gates inside digital computers are actually NAND gates, which are cheaper and sometimes slower but on top of which all other constructs can be built.
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: Most frequently used bitwise operators.
No? I don't know where I got that from; I should take one of Coursera's courses on these matters. In that case, I don't know what the most common operation is when working with logic gates or whether one can be singled out.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]