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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:46:48+00:00 2026-06-14T06:46:48+00:00

How can i apply the xor of two binary strings that represents the bin

  • 0

How can i apply the xor of two binary strings that represents the bin of two characters ?

here is a code

def Xor(a,b):

    ABytes = a.encode('ascii','strict')
    BBytes = b.encode('ascii','strict')

    ABinaries = bin(int(binascii.hexlify(ABytes),16))
    BBinaries = bin(int(binascii.hexlify(BBytes),16))

    #this is what i want to do:
    xor = ABinaries ^ BBinaries 

    return xor

But since the ^ operator does not operate on strings. the code does not work, the problem is that i need to return the binary value of the xor.

And if it worked, how can i get the string value of the xor ?

  • 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-14T06:46:49+00:00Added an answer on June 14, 2026 at 6:46 am

    When you index or iterate bytes in Python 3, you get int values that you can xor:

    >>> a, b = b'abc', b'def'
    >>> c = bytes(x^y for x,y in zip(a, b))
    >>> c
    b'\x05\x07\x05'
    >>> bytes(x^y for x,y in zip(a, c))
    b'def'
    >>> bytes(x^y for x,y in zip(b, c))
    b'abc'
    

    If I wanted this as a bit string for some reason (representation? I certainly wouldn’t calculate with it), I’d use the built-in format, and zero pad each bitstring to 8 bits:

    >>> ''.join(format(x, '08b') for x in c)
    '000001010000011100000101'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here i need a batch file which can apply and create label or base
How do I apply a class to the following so that I can apply
I see from BOL that you can apply permissions to a T-SQL synonym, but
Is there a function I can apply to a string that will return true
Are there any settings I can apply to a SAS session so that I
Is there a subtle trick for template specialization so that I can apply one
I'm trying to create a function that I can apply to a div, and
I have the following CSS that I can apply to an HTML input tag.
I am subclassing uitableviewcell so that i can apply a standard background and text
I know that you can apply CSS in order to style objects in Flex

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.