Apr-22-2018, 10:13 AM
(This post was last modified: Apr-22-2018, 10:13 AM by A_Embedded.)
I am converting a hex string value to hex integer and then shifting the bits after masking to pick only 2 bits out of 32 bits hex value. It works fine when apply if statement to check single expression but when i use && to check another similar expression it gives error as pasted below the console output. Cannot figure out what is going wrong as both expressions are same.
Console result is as follows:
2.7.14
Traceback (most recent call last):
File "C:/GPIO_Test.py", line 31, in <module>
if moder_reg_value==1 && pupdr_reg_value==1:
[b]invalid syntax: <string>, line 31, pos 36
Code is as follows:
Console result is as follows:
2.7.14
Traceback (most recent call last):
File "C:/GPIO_Test.py", line 31, in <module>
if moder_reg_value==1 && pupdr_reg_value==1:
[b]invalid syntax: <string>, line 31, pos 36
Code is as follows:
hex_str_moder= moder_value hex_int_moder= int(hex_str_moder, 16) bin_moder= bin(hex_int_moder) # just to test hex_str_pupdr= pupdr_value hex_int_pupdr= int(hex_str_pupdr, 16) bin_pupdr= bin(hex_int_pupdr) #just to test pin_number+=1 if pin_number==-1: continue bin_moder_shift= hex_int_moder>>(pin_number*2) moder_reg_value= bin_moder_shift & mask bin_pupdr_shift= hex_int_pupdr>>(pin_number*2) pupdr_reg_value= bin_pupdr_shift & mask if moder_reg_value==1 && pupdr_reg_value=1: #moder_reg_value alone works,second expression is problem success+=1 else: fail+=1