当前位置: 首页>>代码示例>>Python>>正文


Python Convert.decimal_to_hexadecimal方法代码示例

本文整理汇总了Python中convert.Convert.decimal_to_hexadecimal方法的典型用法代码示例。如果您正苦于以下问题:Python Convert.decimal_to_hexadecimal方法的具体用法?Python Convert.decimal_to_hexadecimal怎么用?Python Convert.decimal_to_hexadecimal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在convert.Convert的用法示例。


在下文中一共展示了Convert.decimal_to_hexadecimal方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: operation_type_3_4

# 需要导入模块: from convert import Convert [as 别名]
# 或者: from convert.Convert import decimal_to_hexadecimal [as 别名]
 def operation_type_3_4(self,cp,operator,arg,format_type,num_line,dir_type,type_c,is_index,valid_label):
     c = Convert()
     operator = self.get_binary_code(operator)
     flags = self.get_flags(dir_type)
     num_max = 3
     res = arg
     entra = True
     if format_type == 4:
         flags['e']=1
         num_max=5
         if not type_c and valid_label == "relativo":
             self.m_register.append(num_line)
         res = self.current_register.adjust_bytes(arg,num_max,True)
     else:
         if type_c:
             if not self.is_type_c(arg):
                 entra = True
             else:
                 entra = False
                 if not c.is_hexadecimal(arg):
                     arg = c.decimal_to_hexadecimal(arg)
                 res = self.current_register.adjust_bytes(arg,3,True)
         if entra:
             res = self.is_relative_cp(cp,arg)
             if not res:
                 res = self.relative_base(arg)
                 if res:
                     flags['b'] = 1
                 else:
                     res = arg
                     valid_label = False
             else:
                 flags['p'] = 1
             res = self.current_register.adjust_bytes(res,num_max,True)
     if is_index:
         flags['x'] = 1
     if not valid_label:
         flags['b'] = 1
         flags['p'] = 1
     if valid_label == "_":
         flags['b'] = 0
         flags['p'] = 0
     flags = self.flags_string(flags)
     val = operator + flags
     val = str(int(val,2))
     val = c.decimal_to_hexadecimal(val)
     if len(val)==3:
         val = "0"+val
     val = self.current_register.adjust_bytes(val,3,True)
     val += str(res)
     del c
     return val
开发者ID:Juanirow,项目名称:esic,代码行数:54,代码来源:step2.py

示例2: operations_type2_n

# 需要导入模块: from convert import Convert [as 别名]
# 或者: from convert.Convert import decimal_to_hexadecimal [as 别名]
 def operations_type2_n(self,operator,n1):
     operation_code = self.operations[operator]
     c = Convert()
     n1 = c.decimal_to_hexadecimal(n1)
     n1 = n1[:-1]
     del c
     return operation_code + str(n1) + "0"
开发者ID:Juanirow,项目名称:esic,代码行数:9,代码来源:step2.py

示例3: operations_type_2_rn

# 需要导入模块: from convert import Convert [as 别名]
# 或者: from convert.Convert import decimal_to_hexadecimal [as 别名]
 def operations_type_2_rn(self,operator,r,n):
     operation_code = self.operations[operator]
     r = self.registers.get(r,"")
     c = Convert()
     n = c.decimal_to_hexadecimal(n)
     n = n[:-1]
     del c
     obj_code = operation_code + r + str(n)
     return obj_code
开发者ID:Juanirow,项目名称:esic,代码行数:11,代码来源:step2.py

示例4: directive_word

# 需要导入模块: from convert import Convert [as 别名]
# 或者: from convert.Convert import decimal_to_hexadecimal [as 别名]
 def directive_word(self,value):
     c = Convert()
     if not c.is_hexadecimal(value):
         value = int(float(value))
         value = c.decimal_to_hexadecimal(value)
     r = Register("T")
     value = r.adjust_bytes(value,6,True)
     value = r.filter_number(value)
     del r
     return value
开发者ID:Juanirow,项目名称:esic,代码行数:12,代码来源:step2.py

示例5: get_len_program

# 需要导入模块: from convert import Convert [as 别名]
# 或者: from convert.Convert import decimal_to_hexadecimal [as 别名]
 def get_len_program(self):
     c = Convert()
     x = self.bloques[-1]
     ini = self.bloques[0]
     val = c.to_decimal(x.get_load_dir())
     val_len = c.to_decimal(x.length)
     val_ini = c.to_decimal(ini.get_load_dir())
     val = val + val_len - val_ini
     val = c.decimal_to_hexadecimal(val)
     return val
开发者ID:Juanirow,项目名称:esic,代码行数:12,代码来源:bloque.py

示例6: make_T

# 需要导入模块: from convert import Convert [as 别名]
# 或者: from convert.Convert import decimal_to_hexadecimal [as 别名]
 def make_T(self):
     c = Convert()
     dir = self.filter_number(self.init_dir)
     dir = self.adjust_bytes(dir,6,False)
     len_register = len(self.register)/2
     len_hex = c.decimal_to_hexadecimal(len_register)
     hex = self.filter_number(len_hex)
     hex = self.adjust_bytes(hex,2,False)
     register = "T" + dir +hex+self.register
     return register
开发者ID:Juanirow,项目名称:esic,代码行数:12,代码来源:register.py

示例7: get_value_cad_BYTE

# 需要导入模块: from convert import Convert [as 别名]
# 或者: from convert.Convert import decimal_to_hexadecimal [as 别名]
 def get_value_cad_BYTE(self,data):
     string_out =""
     c = Convert()
     r = Register("T")        
     for caracter in data:
         car = str(ord(caracter))
         car = c.decimal_to_hexadecimal(car)
         car = r.filter_number(car)
         string_out+=car
     del c
     return string_out
开发者ID:Juanirow,项目名称:esic,代码行数:13,代码来源:step2.py

示例8: make_M_modificado

# 需要导入模块: from convert import Convert [as 别名]
# 或者: from convert.Convert import decimal_to_hexadecimal [as 别名]
 def make_M_modificado(self,obj_code,cp_num):
     c = Convert()
     cp_num = c.to_decimal(cp_num)
     cp_num = c.decimal_to_hexadecimal(cp_num)        
     dir= self.filter_number(cp_num)
     dir = self.adjust_bytes(dir,6,False)
     edit_bytes = obj_code
     len_bytes = len(edit_bytes)
     len_bytes = self.adjust_bytes(str(len_bytes),2,False)
     register = "M" + str(dir) + str(len_bytes)+"+"+self.name
     return register
开发者ID:Juanirow,项目名称:esic,代码行数:13,代码来源:register.py

示例9: operations_code

# 需要导入模块: from convert import Convert [as 别名]
# 或者: from convert.Convert import decimal_to_hexadecimal [as 别名]
 def operations_code(self,operator,m,is_index):
     r = Register("T")
     c = Convert()        
     op = self.operations[operator]
     op = op+"H"
     op = c.to_decimal(op)
     op = int(op)
     binary = c.decimal_to_binary(op,24)
     binary = c.shift_binary_left(binary,16)
     if is_index:
         binary = c.mask_or(binary,"000000001000000000000000")
     m = c.to_decimal(m)
     m = int(m)
     m = c.decimal_to_binary(m,24)
     binary = c.mask_or(binary,m)
     val = int(binary,2)
     val = c.decimal_to_hexadecimal(val)
     val = r.filter_number(val)  
     val = r.adjust_bytes(val,6,False)
     del r
     del c
     return val
开发者ID:Juanirow,项目名称:esic,代码行数:24,代码来源:step2.py

示例10: Cargadorx

# 需要导入模块: from convert import Convert [as 别名]
# 或者: from convert.Convert import decimal_to_hexadecimal [as 别名]
class Cargadorx():
    def __init__(self,window):
        self.window = window
        self.tabse = Tabse()
        self.lonsc = "0H"
        self.dirsc = "0H"
        self.dirprog = "0H"
        self.direj = "0H"
        self.hexa = Hexadecimal()
        self.convert = Convert()
        self.register = Register("A")
        self.error_indefinido = False
        self.error_duplicado = False

    def show_error(self,msg):
        ##QtGui.QMessageBox.about(self.window,"Error",msg)
        self.window.textEdit_Actions.setText(msg)

    def load_file_name(self,list_obj,dirprog):
        val_int = self.convert.to_decimal(dirprog)
        self.dirprog = self.convert.decimal_to_hexadecimal(val_int)
        self.dirprog = self.register.adjust_bytes(self.dirprog,6,False)+"H"
        self.dirsc = self.dirprog
        self.step_1(list_obj)
        if not self.error_duplicado:
            self.create_memory()
            self.dirsc = self.dirprog
            self.direj = self.dirprog
            self.step_2(list_obj)
            self.init_empty_rows()
            self.tabse.print_tabse()
            if self.error_indefinido:
                self.show_error("Error en simbolo indefinido")
        else:
            self.show_error("Error simbolo duplicado")



    def step_1(self,list_obj):
        for list_n in list_obj:
            for n in list_n:
                if len(n) > 0:
                    if n[0] == "H":
                        self.step_h(n,1)
                    elif n[0] == "D":
                        self.step_1_d(n)
            self.dirsc = self.hexa.plus(self.dirsc,self.lonsc)

    def step_h(self,n,step):
        name = n[1:7]
        name = name.strip()
        self.lonsc = n[13:]+"H"
        if step == 1:
            if not self.tabse.exist_node(name):
                self.tabse.insert_section(name,self.dirsc,self.lonsc)
            else:
                ##print name
                self.error_duplicado = True

    def step_1_d(self,n):
        num = (len(n)-1)/12
        it = 0
        # print "num",num,len(n)
        while it < num:
            index1 = (it * 12)+1
            index2 = index1 + 6
            index3 = index2 + 6
            name = n[index1:index2].strip()
            #print "name",name 
            if index3 >= len(n):
                len_r = n[index2:]+"H"
            else:
                len_r = n[index2:index3]+"H"
            if not self.tabse.exist_node(name):
                val = self.hexa.plus(len_r,self.dirsc)
                self.tabse.insert_variable(name,val)
            else:
                print "error",name
                self.error_duplicado = True
            it += 1

    def step_2(self,list_obj):
        for list_n in list_obj:
            for n in list_n:
                if len(n) > 0:
                    if n[0] == "H":
                        self.step_h(n,2)
                    elif n[0] == "T":
                        self.charge_obj_code(n)
                    elif n[0] == "M":
                        self.change_m_register(n)
                    elif n[0] == "E":
                        self.reg_e(n)
            self.dirsc = self.hexa.plus(self.dirsc,self.lonsc) 

    def reg_e(self,r):
        if len(r) > 1:
            val = r[1:] + "H"
            self.direj = self.hexa.plus(self.dirsc,val)

#.........这里部分代码省略.........
开发者ID:Juanirow,项目名称:esic,代码行数:103,代码来源:Cargadorx.py

示例11: Simuladorx

# 需要导入模块: from convert import Convert [as 别名]
# 或者: from convert.Convert import decimal_to_hexadecimal [as 别名]

#.........这里部分代码省略.........
		self.window.tableWidget_2.setVerticalHeaderItem(8, item)

	def init_registers(self):
		it = 0
		while it < 9:
			item_text = QtGui.QTableWidgetItem("FFFFFFFH")
			self.window.tableWidget_2.setItem(it,0,item_text)
			it += 1

	def set_register(self,reg_num,val):
		val_hex = self.register.adjust_bytes(val,6,False)
		val_hex = self.hexa.change_hexadecimal(val_hex)
		item_text = QtGui.QTableWidgetItem(val_hex)
		self.window.tableWidget_2.setItem(reg_num,0,item_text)

	def get_register(self,reg_num):
		item = self.window.tableWidget_2.item(reg_num,0)
		return str(item.text())

	def carga(self,list_obj,dirprog):
		self.cargador = Cargadorx(self.window)
		self.cargador.load_file_name(list_obj,dirprog)
		cp = self.cargador.direj
		self.set_register(self.REG_CP,cp)
		self.show_next_instr()
		self.end_program = self.cargador.dirsc
		if self.cargador.error_duplicado:
			QtGui.QMessageBox.about(self,"Error","Error simbolo duplicado")
		elif self.cargador.error_indefinido:
			QtGui.QMessageBox.about(self,"Error","Error simbolo indefinido")


	def increment_cp(self,num):
		num_hexa = self.convert.decimal_to_hexadecimal(num)
		cp = self.get_register(self.REG_CP)
		res = self.hexa.plus(num_hexa,cp)
		self.set_register(self.REG_CP,res)

	def show_next_instr(self):
		op = self.get_operation()
		self.window.label_sig.setText(op[1])
	
	def get_operation(self):
		cp = self.get_register(self.REG_CP)
		value = self.get_data_form_mem(cp,1)
		val = value[0]
		val2 = value[1]
		val_d = int(self.convert.to_decimal(val2+"H"))
		val_d = val_d & 12
		value = val + self.convert.decimal_to_hexadecimal(str(val_d))[:-1]
		tip = "Error"
		op = self.operations_1.get(value,"Error")
		if not op == "Error":
			tip = "1"
		else:
			op = self.operations_2.get(value,"Error")
			if not op == "Error":
				tip = "2"
			else:
				op = self.operations_3.get(value,"Error")
				if not op == "Error":
					tip = "3"
		return [value,op,tip]
		
	##regresa los datos de una localidad y las licalidades 
	#siguientes 
开发者ID:Juanirow,项目名称:esic,代码行数:70,代码来源:simuladorx.py

示例12: increment_cp

# 需要导入模块: from convert import Convert [as 别名]
# 或者: from convert.Convert import decimal_to_hexadecimal [as 别名]
 def increment_cp(self, num):
     c = Convert()
     num = c.decimal_to_hexadecimal(num)
     cp = self.get_CP_value()
     cp = self.hex.plus(cp, num)
     self.set_cp_value(cp)
开发者ID:Juanirow,项目名称:esic,代码行数:8,代码来源:Cargador.py

示例13: __init__

# 需要导入模块: from convert import Convert [as 别名]
# 或者: from convert.Convert import decimal_to_hexadecimal [as 别名]
class Segment:
    def __init__(self):
        self.index = 0
        self.list_n = []
        self.conv = Convert()
        self.reg = Register("X")
        self.hexa = Hexadecimal()
        self.last_code = 0

    ## regresa el segmento actual
    def get_segment(self):
        return self.list_n[self.index]
    
    ##crea un segmento con el nombre especificado
    # @param name nombre del segmento que se creara 
    def new_segment(self,name):
        self.index = len(self.list_n)
        self.list_n.append(NodoS(name,self.index))


    ##inserta una etiqueta a la tabla de simbolos y si esta ya se encuentra marca un error
    #@param name simbolo que se intentara insertar a la tabla
    #@param dir_val direccion o valor del simbolo
    #@param sym_type tipo del simbolo el cual puede ser relativo o absoluto
    #@param lineno numero de linea donde se encontro la etiqueta
    def insert_symbol(self,name,dir_val,sym_type,lineno,bloque_index,externo = False):
        if self.exist_symbol(name):
            self.insert_error(str(lineno),"etiqueta previamente definida")
        else:
            sym = Symbol(name,dir_val,sym_type,bloque_index,externo)
            self.get_segment().symbols.append(sym)
            
    def exist_symbol(self ,name):
        for it in self.get_segment().symbols:
            if it.get_name() == name:
                return it
        return None
        
    ##checa si en el diccionario de errores ya se inserto un error en esa linea de codigo
    #y si no es asi la inserta 
    #@param line linea de codigo donde se encontro un error
    #@param text cadena que se genera en el error
    def insert_error(self,line,text):
        l = int(line) - self.last_code -1
        if not str(l) in self.get_segment().errors and l >= 0:
            self.get_segment().errors[str(l)]= text
    
    ##checa si en el diccionario de advertencias ya se inserto un error en esa linea de codigo
    #y si no es asi la inserta 
    #@param line linea de codigo donde se encontro un warnind
    #@param text cadena que se genera en el warning
    def insert_warning(self,line,text):
        l = int(line) - self.last_code
        if not str(l) in self.get_segment().warnings:
            self.get_segment().warnings[str(line)] = text
            
    ##aumenta el contador de programa 
    #@param increment cantidad en hexadecimal que se le agregara al CP
    def increment_PC(self,increment):
        num1 = self.get_segment().pc[-1]
        if not self.conv.is_hexadecimal(str(increment)):
            increment = self.conv.decimal_to_hexadecimal(increment)
        val = self.hexa.plus(num1,increment)
        if val == "H":
            val = "0H"
        val = self.reg.adjust_bytes(val,6,False)+"H"
        self.get_segment().bloques.set_last_cp(val)
        self.get_segment().pc.append(val)
        self.get_segment().num_bloque.append(self.get_segment().bloques.get_index())
        
    ## calcula el tamaño del programa 
    #@return regresa en hexadecimal el tamaño del programa
    def get_len_program(self):
        return  self.get_segment().bloques.get_len_program()

    ## genera y completa la tabla de bloques de todos los segmentos 
    def genera_tabla_bloques(self):
        for it in self.list_n:
            it.bloques.gen_table()
    ## regresa un segmento en un index especificado   
    # @param index posicion del segmento que se quiere
    def get_segment_at(self,index):
        return self.list_n[index] 
    
    ## imprime los resultados de un segmento 
    # @param extension es la extencion que tendran los archivos de salida de los segmentos       
    def print_results(self,extension):
        for it in self.list_n:
            # print it.errors,it.errors_s
            it.archivo_intermedio(extension)
            if len(it.errors) == 0 and len(it.errors_s) == 0:
                it.archivo_objeto(extension)
            print "Errors", len(it.errors)+len(it.errors_s)

    def get_num_errors_all(self):
        cant = 0
        for it in self.list_n:
            cant += len(it.errors_s)
            cant += len(it.errors)
        return cant 
开发者ID:Juanirow,项目名称:esic,代码行数:102,代码来源:segment.py


注:本文中的convert.Convert.decimal_to_hexadecimal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。