&~ in a formula.

Solved
Anonymous user -  
[Dal] Posted messages 6205 Registration date   Status Contributeur Last intervention   -
Hello,

I am constantly looking for ways to optimize my code.
This morning I came across a rather strange formula that I don't understand...

Can you explain to me what this piece of code does:

 int nbr = (sizeof(int) -1) & ~(sizeof(int) -1) ; if (nbr ...) { [...] } 


It’s mainly the "& ~" part that intrigues me, is it an operator?
What does it do?

Thank you for your insights!

Configuration: Windows / Chrome 55.0.2883.87

1 réponse

[Dal] Posted messages 6205 Registration date   Status Contributeur Last intervention   1 108
 
Hello astrocurious,

& and ~ are two bitwise operators in C

http://www.bien-programmer.fr/bits.htm

Dal
1
Anonymous user
 
Thank you very much, DAL, it's very clear on your site!
0
[Dal] Posted messages 6205 Registration date   Status Contributeur Last intervention   1 108
 
It's not my site, it's Emmanuel Delahaye's :)
0