bitwise shift?

Sherm Pendley spamtrap at dot-app.org
Wed Apr 25 17:10:54 EDT 2007


desktop <fff at sss.com> writes:

> for k in range(10, 25):
>       n = 1 << k;
>
> I have never read Python before but is it correct that 1 get
> multiplied with the numbers 10,11,12,12,...,25 assuming that 1 << k
> means "1 shift left by k" which is the same as multiplying with k.

Shift left is *not* the same as multiplying by k. It is the same as multi-
plying by 2^k. That is, 1<<10 = 1024, 1<<11 = 2048, 1<<12 = 4096, etc.

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net



More information about the Python-list mailing list