THIS Will Make Your Colleagues Mad In Python #learnpython #python #programming

preview_player
Показать описание
This will make your colleagues mad in Python. #learnpython #python #programming

▶ Become job-ready with Python:

▶ Follow me on Instagram:
Рекомендации по теме
Комментарии
Автор

A modern C or C++ compiler will optimise multiplication or division by powers of two into shift operations.

davidgillies
Автор

Wow! Another way to make my code more confusing, and with the -~ operators, too! 💀

MonkFeet
Автор

There’s a video out there that did this on fibonacci numbers to run them more efficiently.

fractalmadness
Автор

It is more efficient to use it in enum numbering, it immediately acts as a header

kadircalloglu
Автор

i notice in these vids the value are usually put as number: Int = 100 doesnt python already recognise integers based on how theyre inputted? Like if you put number = 2.5 it wouldnt need to be typecasted as a float because the . is there?

Scousestrongmanfan
Автор

I do this very much, but only in VHDL 😂

KennethHaldbk
Автор

The sad bit is that for some reason bitwise division or multiplication with 2 like this is somehow slower than using * 2 or // 2, same with & 0b111 instead of % 8 (on this I know the & checks all bits instead of just what is necessary like with modulo), etc. I wonder why this is, or if there is a way to make bitwise operations outperform arithmetic.

DumToasty
Автор

Makes sooo much sense now. Shift left, you’re shifting to a factor of 2^1 = 2. Shift right, you’re shifting to a factor of 1/(2^1) = 1/2 = 0.5.

Thanks for the tip!

miss-astronomikal-mcmxcvii
Автор

Have you studied the Bitcoin Code and found the halving?

steff
Автор

Do not do this, this is silly, only use bit shift operators if you actually want to bit shift logically.

janisir
Автор

Two questions, if you need Performance why Python?
And a 2nd one, why cant Python make this optimization under the hood automatically?

michaelschmid
Автор

Sure, but what’s the use? Can someone explain where and how this could be useful?

tigerbojiteol
Автор

yeah, the exampls is silly, I give a usefule example.
(quake 3 )fast inverse square root algorithm, it use bitwise operations and magic constant.

to calculate ipv4 address subnet mask, you have to use bitwise operator.

BohonChina
Автор

Its not funny but actually practical when coding in binary

Zarya.
Автор

Some low level programming in python 😂 love it

Grinwa
Автор

"Right to divide, and left to multiply", sounds really political lol

florunio
Автор

What about right shift of uneven number?

jgoep
Автор

he keeps finding more tricks somebody stop this man

not_eagleye
Автор

its silly, its like using micreoscope to observe.. birds. Python is a slow language good for prototyping, binary operations usually make sense for performant code that allows for real memory management

WojciechowskaAnna
Автор

I'm 🇺🇿
A>>B -> A/2**B
A<<B -> A*2**B

BehruzZoirov-ifkw