473,323 Members | 1,537 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

>> and << operators?

What does >and << do?

Googling on them and they are just ignored...

Aug 22 '08 #1
2 1248
On Fri, Aug 22, 2008 at 6:30 PM, defn noob <ci**********@yahoo.sewrote:
What does >and << do?
Normally they are bitwise operators:
>Shifts bits right
<< Shifts bits left

print 1 << 3
8

because 8 = 00001000 in binary

Regards
Aug 22 '08 #2
On Aug 22, 5:43*pm, "Medardo Rodriguez (Merchise Group)"
<med....@gmail.comwrote:
On Fri, Aug 22, 2008 at 6:30 PM, defn noob <circularf...@yahoo.sewrote:
What does >and << do?

Normally they are bitwise operators:>Shifts bits right

<< Shifts bits left

print 1 << 3
8

because 8 = 00001000 in binary

Regards
An example of usage:

import gmpy
def Collatz(n):
#
# if n is odd, multiply by 3 and add 1
# if n is even, divide by 2 until n becomes odd
# repeat until n == 1
#
while n>1:
print n,
f = gmpy.scan1(n) # find position of first 1-bit
if f>0: # it's even, so...
n = n >f # ...remove factors of 2 in one fell swoop
else: # it's odd
n = 3*n + 1
print n

print 'Collatz(11):',
Collatz(11)

print

print 'Collatz(27):',
Collatz(27)

## Collatz(11): 11 34 17 52 13 40 5 16 1
##
## Collatz(27): 27 82 41 124 31 94 47 142 71
## 214 107 322 161 484 121 364
## 91 274 137 412 103 310 155
## 466 233 700 175 526 263 790
## 395 1186 593 1780 445 1336
## 167 502 251 754 377 1132 283
## 850 425 1276 319 958 479 1438
## 719 2158 1079 3238 1619 4858
## 2429 7288 911 2734 1367 4102
## 2051 6154 3077 9232 577 1732
## 433 1300 325 976 61 184 23 70
## 35 106 53 160 5 16 1
Aug 22 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Pedro Werneck | last post by:
Hi list I'm trying to implement a new type in a C extension and it must support some binary operators, like &, |, ^, << and >>. With &, | and ^, the method must receive another object of the...
1
by: PengYu.UT | last post by:
I heard that != >= > <= operators are defined based on the operator == <. Could you tell me which header file defines the four operators? Best wishes, Peng
17
by: Peter Bromley | last post by:
The following code snippet does not seem to work correcly unsigned __int64 result = 0xFFFFFFFFFFFFFFFF; result = result << 64; Debugger.WriteLine(System::String::Format(S"{0:X16}",...
7
by: Rocky Moore | last post by:
I have a web site called HintsAndTips.com. On this site people post tips using a very simply webform with a multi line TextBox for inputing the tip text. This text is encode to HTML so that no...
4
by: jelle | last post by:
Hi, I use python quite a bit to couple different programs together. Doing so has been a _lot_ easier since subprocess came around, but would really like to be able to use the succinct shell...
5
by: Suman | last post by:
Having had a look at the C++ FAQ, comp.lang.c++ & comp.std.c++ archives and Stroustrup's FAQs (particularly the following: <url:http://www.research.att.com/~bs/bs_faq2.html#overload-dot/>) I am...
10
by: onkar | last post by:
#include<stdio.h> int main(void){ printf("%d %d\n",32<<1,32<<0); printf("%d %d\n",32<<-1,32<<-0); <----------------------------------see here printf("%d %d\n",32>>1,32>>0); printf("%d...
9
by: =?Utf-8?B?QmVu?= | last post by:
Hi, I'm trying to figure out the purpose of these operators. Now, I know what they do. They shift bits either left or right. But I don't know why would anybody want to do that. I've never seen...
14
by: Michael | last post by:
Since the include function is called from within a PHP script, why does the included file have to identify itself as a PHP again by enclosing its code in <?php... <?> One would assume that the...
7
by: Nathan Sokalski | last post by:
Something that I recently noticed in IE6 (I don't know whether it is true for other browsers or versions of IE) is that it renders <br/and <br></br> differently. With the <br/version, which is what...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.