+ 4
Hi guys can I have the result of bitwise operators without turning the operands into the binary mod?
11 odpowiedzi
+ 8
Mbengue Mbor In case you weren't aware, I wanted to mention those challenges aren't a real test of your knowledge or measure of your skill.
Nor are those challenges any reflection of good coding practices. Actually, quite the opposite. I would likely fire anyone who writes code like many of the brain teaser nonsense garbage used in those challenges. 😉
So, don't worry so much that your brain can't compute obscure expression statements like an overclocked 8-bit 6502 CPU. 😜
It's not required to be a brilliant programmer. 🤓
+ 7
Well, yes
print(25<<3)
print(16&5)
print(89|14)
print(49^26)
print(~17)
+ 7
🤦♂️🤷♂️
Anna I guess you went too far with your answer after the very first line "Well, yes" 😂🤣
+ 6
? Then don't use it
+ 6
So you want to know how the bitwise operators work? You can't do most of them in your head unless your IQ is at least 148
+ 6
Everyone probably knows this, but in the off chance it benefits someone...
Instead of actually writing them in binary, it's faster for me to break them into powers of 2. Let me explain with an example.
89 | 14
= (64+16+8+1) | (8+4+2)
(for OR, we remove the duplicates)
= 64+16+8+1 + 4+2
= 89+6
= 95
Similarly for 89 & 14, the answer is 8 because that's the only one that occurs in both.
With some practice, it's possible to do this in your head. Though I can't say I'd appreciate these questions in the Challenges.
+ 3
I know these two only since it's impossible to know all:
x<<y = x*(2**y)
x>>y = x/(2**y)
+ 2
I mean in the challenge if I must give the answer of print (25<<3) or print(16&5) in few seconds
+ 2
Thanks I know how to evaluate them but I have a luck of time in the challenges
+ 2
Thank you
+ 1
Thanks but I don't say the print function