Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

shifting result using <<

enter image description hereI want to calculate the string value that is return from a function, which is a hex value in string type. I used int(,16) to convert it to int, but I still cannot use the shift operator, any reason why?

       reg_dic= { "REG_RX_PKT_CNT_L_ADDR":"00000", 
               "REG_RX_PKT_CNT_H_ADDR":"00001", 
               "REG_RX_PKT_CNT_B_L_ADDR":"0001F", 
               "REG_RX_PKT_CNT_B_H_ADDR":"00020"
                 }
result_l, value_low = self.check_regs(portnum, list(reg_dic.values())[pair])
result_h, value_high = self.check_regs(portnum,list(reg_dic.values())[pair+1])
value_low = int(value_low, 16)
value_high = int(value_high, 16)
print(type(value_low))
value = value_high << 18 + value_low
print(list(reg_dic.keys())[pair], value_low)
print(list(reg_dic.keys())[pair+1], value_high)
print("Counter Sum is:",  hex(value)) 

Result I got is bunch of 0 and I have to break it.

Thanks in adv
enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Your NEW problem is one of precedence. + has higher precedence than << so your statement is parsed like value = value_high << (18 + value_low).

To solve this, add parentheses explicitly, like: value = (value_high << 18) + value_low.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading