Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6721347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:19:11+00:00 2026-05-26T09:19:11+00:00

I have the following code in Python: for i in range(4): if self.start ==

  • 0

I have the following code in Python:

for i in range(4):
  if self.start == self.corners[i]:
    self.visitedCorners += (1 << i)

I’m working with co-ordinates. self.start and self.corners are co-ordinates.

So with the code on the top I want to check whether the start is a corner.
If the start is the same of a corner, I do that shift. But, how does that shift work?

I don’t want any other code; I just want to understand this code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:19:11+00:00Added an answer on May 26, 2026 at 9:19 am

    All that 1 << i does is produce the number with the i-th least significant bit set to 1 and all other bits set to 0:

    >>> for i in range(4): print bin(1 << i)
    ... 
    0b1
    0b10
    0b100
    0b1000
    

    In the code, self.visitedCorners is a bit mask, where the four least significant bits correspond to the four corners. Each iteration of the for i loop sets the corresponding bit in self.visitedCorners to 1 (provided the if condition holds).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following (Python) code to check if there are any rows or
I have the following python code using the twisted API. def function(self,filename): def results(result):
I have the following Python code: import xml.dom.minidom import xml.parsers.expat try: domTree = ml.dom.minidom.parse(myXMLFileName)
I have the following Python code: cursor.execute("INSERT INTO table VALUES var1, var2, var3,") where
I have following code in my application. [self.navigationController pushViewController:x animated:YES]; It will push a
I have the following code: #!/usr/bin/env python import sys from PyQt4 import QtGui, QtCore
I have the following code that is attempting to start each of the commands
Kinda knew to Python: I have the following code: def printCSV(output, values, header): 63
Look at the following Python code: def function(x): return x, x+1 sequence = range(5)
A simple question on a python module. Let's say I have the following code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.