For further actions, you may consider blocking this person and/or reporting abuse
Read next
![nanduanilal profile image](https://media.dev.to/cdn-cgi/image/width=100,height=100,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1447642%2F93efd81f-49aa-4ba6-94cd-3d8b3aafbd45.jpg)
Why is Meta spending so much on Open Source AI?
nandu 🦦 -
![lincpa profile image](https://media.dev.to/cdn-cgi/image/width=100,height=100,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1314341%2F6ec48582-ff0d-489d-9e61-73eb1ce5551f.png)
Traditional IT theory (OOP, FP and hardware architecture, etc.) are pseudoscience (by Math-based Warehouse/Workshop Model)
Lin Pengcheng -
![ifrah profile image](https://media.dev.to/cdn-cgi/image/width=100,height=100,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F726378%2F6b87acd0-4959-489c-85af-efdab32e67c9.png)
What Are Some of Your Favourite Visual Studio Code Extensions?
ifrah -
![daymannovaes profile image](https://media.dev.to/cdn-cgi/image/width=100,height=100,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1456517%2F143c4278-c0bf-4e53-bea2-50f3b5328a4f.jpeg)
dominando a essência do programação: uma introdução filosófica
Dayman Novaes -
Top comments (8)
Ok, here's a neat trick in C to swap the contents of two variables without a temporary variable:
The exact theory behind this is a bit tricky to understand through formal explanation, but is pretty easy to understand by running through it with concrete numbers:
This has limited practical value today because memory is cheap, but is still sometimes used in code for microcontrollers that have very limited memory. It actually works in any language that supports bitwise XOR and has the same rules as C for bit width. Theoretically the variables don't even have to be the same type, just the same bit width, though C makes you use type casting if they aren't the same type.
This is awesome
No, it is actually awful please never even think about using it. Modern compiler try to infer semantics, and
is such a known pattern that compiler know that this is a variable switch so theyll optimize it anyways.
And you can read it worse.
Not sure if this qualifies but a lot of people don't know about the f-string feature in python. You can do for example :
import os
file = 'test.txt'
print(f"File is located at: {os.path.realpath(file)}")
What has this to do with bit manipulation?
Lol I think I totally read over your question too quickly or it must have been very late when I wrote that.
Something like this:
function isOdd (num) {
return (num & 1) === 1;
}
the 1 (in num & 1) is used as a mask to check whether the number num is odd or not. If the last bit is set to 1 we know it is odd otherwise it is not odd.