10进制怎么换4进制

10进制28.5625怎么换成4进制

思路:先将键盘接收的16进制数转换为2进制,然后由2进制转换为10进制
提示:键盘接收时可接收0-ffffh之间的任意数且可循环转换,比如要将12H转换为十进制,只需输入12然后回车即可,其它数同上,当然也包括你说的指定的四位16进制数
code segment
main proc far
assume cs:code
start:
call hexibin ;16-2
call crlf ;换行

call binidec ;2-10
call crlf

jmp main ;get next input
ret
main endp

hexibin proc near
mov bx,0 ;clear BX for number
newchar:
mov ah,01h ;keyboard input
int 21h ;call DOS
sub al,30h ;ASCII to binary
jl exit ;jump if<0
cmp al,10d ;is it > 9d
jl add_to ;yes,so it‘s digit

;not digit(0-9),may be letter(a to f)
sub al,27h ;convert ASCII to binary
cmp al,0ah ;is it <0a hex?
jl exit ;yes,not letter
cmp al,10h ;is it > 0f hex?
jge exit ;yes,not letter
;is hex digit,add to number in BX
add_to:
mov cl,4
shl bx,cl
mov ah,0
add bx,ax
jmp newchar
exit:
ret
hexibin endp

binidec proc near
mov cx,10000d
call dec_div
mov cx,1000d
call dec_div
mov cx,100d
call dec_div
mov cx,10d
call dec_div
mov cx,1d
call dec_div
ret

dec_div proc near
mov ax,bx ;number low half
mov dx,0 ;zero out high half
div cx
mov bx,dx ;remainder into BX
mov dl,al ;quotient into DL
;print the contents of DL on screen
add dl,30h ;convert to ASCII
mov ah,02h
int 21h
ret
dec_div endp
binidec endp

crlf proc near
mov dl,0ah
mov ah,02h
int 21h

mov dl,0dh
mov ah,02h
int 21h
ret
crlf endp

code ends
end start
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-12-16
28.5625把整数部分 与小数部分 分开 看;整数 除以4,取余数的逆序数 得 130;小数部分乘以4,取首位得到 0.21所以结果为 130.21
第2个回答  2013-12-16
恕小弟无知,有四进制么。小弟只知道十六,十,八,二进制。
第3个回答  2013-12-16
只有十六、十、八、二进制!
相似回答