I want to convert string 1F to hex 1F in Python, what should I do?

2024/11/15 17:53:00
num="1F"
nm="1"
nm1="2"
hex(num)^hex(nm)^hex(nm1)

I wrote it like the code above, but hex doesn't work properly.

I want to convert the string to hexadecimal, and I want an xor operation of the converted value.

What should I do?

Answer

The variable num can be converted to int using int(num, 16). Other variables nm, nm1 are just integers in form of strings. to convert them use int(nm), int(nm1)

num = "1F"
nm = "1"
nm1 = "2"result = int(num, 16) ^ int(nm) ^ int(nm1)
print(result)> 28
https://en.xdnf.cn/q/119635.html

Related Q&A

How to call a function in a Django template?

I have a function on my views.py file that connects to a mail server and then appends to my Django model the email addresses of the recipients. The script works good. In Django, Im displaying the model…

Remove duplicates from json file matching against multiple keys

Original Post = Remove duplicates from json dataThis is only my second post. I didnt have enough points to comment my question on the original post...So here I am.Andy Hayden makes a great point - &quo…

Merging CSVs with similar name python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 8…

urllib.error.HTTPError: HTTP Error 403: Forbidden

I get the error "urllib.error.HTTPError: HTTP Error 403: Forbidden" when scraping certain pages, and understand that adding something like hdr = {"User-Agent: Mozilla/5.0"} to the h…

Compare multiple file name with the prefix of name in same directory

I have multiple .png and .json file in same directory . And I want to check where the files available in the directory are of same name or not like a.png & a.json, b.png & b.json

how to make a unique data from strings

I have a data like this . the strings are separated by comma."India1,India2,myIndia " "Where,Here,Here " "Here,Where,India,uyete" "AFD,TTT"What I am trying…

How to read complex data from TB size binary file, fast and keep the most accuracy?

Use Python 3.9.2 read the beginning of TB size binary file (piece of it) as below: file=open(filename,rb) bytes=file.read(8) print(bytes) b\x14\x00\x80?\xb5\x0c\xf81I tried np.fromfile np.fromfile(np…

How to get spans text without inner attributes text with selenium?

<span class="cname"><em class="multiple">2017</em> Ford </span> <span class="cname">Toyota </span>I want to get only "FORD" …

List of 2D arrays with different size into 3D array [duplicate]

This question already has answers here:How do you create a (sometimes) ragged array of arrays in Numpy?(2 answers)Closed last year.I have a program that generating 2D arrays with different number of r…

How can I read data from database and show it in a PyQt table

I am trying to load data from database that I added to the database through this code PyQt integration with Sqlalchemy .I want the data from the database to be displayed into a table.I have tried this …