python - Converting Ints into binary / hex with ^ operator -


i have 2 variables, read , out.

read string e.g. "1101", next there out int following same binary format such 100000 etc. need perform operation if 2 variables are

>>1000 >>1011 output: 0011 

i have tried use read ^ out, have tried convert them hex , turn out ints other numbers ( 2-9 ). output needs int or binary literal ( 0b0101 )

edit: value sent off function write( 0x20, 0x13, out ). whenever gets sent python automatically converts int if binary, causes problems later on.

^ works on ints.

you can convert strings integers specified base:

int(x=0) -> integer

int(x, base=10) -> integer

for opposite conversion there's bin().

in [1]: bin(int('1000', 2) ^ int('1011', 2)) out[1]: '0b11' 

the rest matter of string formatting. if want have in 4 digits , without prefix, take @ arshajii's answer.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -