Reputation: 61
I am getting input from user as string, The string is converted into hex and that values are printed.. the code is as follows..
STX = input("enter STX Value")
Deviceid = input("enter device id")
subid = input("enter address of the Device and load details")
Comnd = "41"
Data = "01"
load = input("enter the load should be on or OFF,if on type 01 other wise type 00")
Eor = hex(int(STX, 16) ^ int(Deviceid, 16) ^ int(subid, 16) ^ int(Comnd, 16) ^ int(Data, 16) ^ int(load, 16))
Addsum = int(STX, 16)+int(Deviceid, 16)+int(subid, 16)+int(Comnd, 16)+int(Data, 16)+int(load, 16)+int(Eor, 16)
The output of the program is as follows
enter STX Value"F7"
enter device id"03"
enter address of the Device and load details"83"
enter the load should be on or OFF,if on type 01 other wise type 00"01"
0x36
the add sum is
0x1f6
In the last line 0x1f6 i want omit '1'. how can i do that.. thanks for your help...
Upvotes: 1
Views: 94
Reputation: 82899
You can use the modulo operator %
to get the last two digits and then convert that number back to hexadecimal format, using either the hex
function or a format string.
>>> m = 0x106 % 16**2
>>> print("0x%02x" % m)
0x06
Upvotes: 1