You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

29 lines
821 B

#Software Code Class_Byte
class Byte():
def _init_(self,value):
self.value= int(value)
def set_bit(self,bitnr,val):
self.nrp= 1 << (bitnr - 1)
self.nrn= ~self.nrp
if val == True:
self.value= self.value | self.nrp
if val == False:
self.value= self.value & self.nrn
def is_set(self,bitnr):
self.nrp= 1 << (bitnr - 1)
if self.value & self.nrp != 0:
return True
else:
return False
def toggle_bit(self,bitnr):
pos= 1<<(bitnr-1)
self.value= self.value ^ pos
def swap_bit(self,bitnr1,bitnr2):
if (((self.value & (1 << bitnr1)) >> bitnr1) ^ ((self.value & (1 << bitnr2)) >> bitnr2)) == 1:
self.value ^= (1 << bitnr1)
self.value ^= (1 << bitnr2)