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 8883057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:43:25+00:00 2026-06-14T20:43:25+00:00

I am having a problem with an xor search. I have an array composed

  • 0

I am having a problem with an xor search.
I have an array composed of binary values. My list contains 1000 distinct binary values, and I want to time how long it takes for a double loop to find an element in the list. Therefore for a double loop search, I expect it to go through the loop [(1) + (2) +(3)+…+(1000)] = 500500 times. [n(n+1) / 2]

I use the bitwise_xor in the following code

from numpy import bitwise_xor

count = 0
for word1 in listOutTextnoB:
    for word2 in listOutTextnoB:
        count+=1
        if bitwise_xor(word1,word2)==0:
            break
print "count"

Unfortunately, when I print count, I get count = 1,000,000

If I change the if statement to

if bitwise_xor(word1,word2):
      break

count is 1000

I also tried to do:

if word1^word2==0:
       break

but it gives me “TypeError: unsupported operand type(s) for ^: ‘str’ and ‘str'”

A working example would be:
1101110111010111011101101110110010111100101111001 XOR 1101110111010111011101101110110010111100101111001
it should give me 0 and exit the inner loop

What is wrong with 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-06-14T20:43:27+00:00Added an answer on June 14, 2026 at 8:43 pm

    ^ works on integers, not arrays, so that is not surprising.

    I don’t know why you used strings but:

    from numpy import bitwise_xor
    
    listOutTextnoB = range(1000)
    count = 0
    for word1 in listOutTextnoB:
        for word2 in listOutTextnoB:
            count+=1
            if bitwise_xor(word1,word2)==0:
                break
    print "count", count
    

    prints

    count 500500
    

    as you predict.

    EDIT: yes, you should be doing

    if int(word1) ^ int(word2) == 0:
        break
    

    bitwise_xor is actually returning ‘NotImplemented’ for every string, string input.

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

Sidebar

Related Questions

I am reading XOR linked list (from Wikipedia).But I am having some problems in
Im having problem in my UIscrollView ,this is what I have done: Whenever a
I'm having problem with datagrid view. I have attached an image with the code
hello I am having problem related to https:// . I have used FB.getLoginStatus(function(response) function
I'am having problem in accessing json array elements. Below is the response when i
Having problem with this bit of code qith jQuery. it should pick the values
i having problem with draw image in applet. i want to display all images
Simple question here. Having a problem with the XOR operator (^). I can XOR
Im having problem trying to join 3 tables, every time I run the query
Im having problem with cordova xcode app. I already have my html page setup.

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.