Ad
How To XOR Two Hex Values If One Of Them Was A String?
below is a snippet of the problem
string = "test"
for index, character in enumerate(string):
value = hex(ord(character)) ^ 0xababab
This code is returning an error that it cannot XOR a string and an integer. So how can I get python to deal with the hex(ord(character))
as an integer and not a string?
I tried casting it to an int by adding int(hex(ord(character)))
but that returns an error of: Invalid literal for int with base10
Ad
Answer
Just use ord
, it's int.
for c in s:
print(ord(c) ^ 0xababab)
As you can see, these are equivalent:
1 == 0x01 # True
Ad
source: stackoverflow.com
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module
Ad