Translation 32HEX -> DEC...
ZXNet echo conference «code.zx»
From Roman Petrov → To Felix Knajzev 4 May 2000
Hello Felix!
On Sunday April 30 2000 Felix Knajzev wrote to All:
FK> Throw, please, a program at me for converting a 32-bit HEX number to
FK> decimal.
This is the kind of thing used in NeOS. I know it's not the fastest, but
works and removes leading zeros:
At the input: IX - high 16 bits, HL - low 16 bits.
=== Cut ===
PNUM32 ld a,xh
or xl
ld b,0
jr z,PNUM161-6
ld bc,#3b9a
ld de,#ca00
call PCIF32
ld bc,#5f5
ld de,#e100
call PCIF32
ld bc,#98
ld de,#9680
call PCIF32
ld bc,#f
ld de,#4240
call PCIF32
ld bc,#1
ld de,#86a0
call PCIF32
ld bc,0
ld de,#2710
call PCIF32
ld b,0
jr PNUM161
ld de,10000
call PCIFRA
PNUM161 ld de,1000
call PCIFRA
ld de,100
call PCIFRA
ld de,10
call PCIFRA
inc b
ld de,1
PCIFRA xor a
sbc hl,de
inc a
jr nc,$-3
add hl,de
dec a
jr nz,PCIFRA1
ld a,b
and a
ret z
xor a
PCIFRA1 inc b
add a,48
ldc,a
jp PUTCH
PCIF32 xor a
sbc hl,de
push hl
push ix
pop hl
sbc hl,bc
push hl
pop ix
pop hl inc a
jr nc,PCIF32+1
add hl,de
push hl
push ix
pop hl
adc hl,bc
push hl
pop ix
pop hl
dec a
ret z
add a,48
ld c,a
jp PUTCH
=== Cut ===
Bye, Felix! Megus/Brainwave^X-Project. [I.ZX] [NeOS]
From Aleksey Malov → To Felix Knajzev 4 May 2000
Greetings, Felix!
Sun 30 Apr 2000 at 22:15:57 Felix Knajzev and All were talking
on the topic Translation 32HEX -> DEC....
FK> Throw, please, a program at me for converting a 32-bit HEX number to
FK> decimal.
I would love to throw it, but I’m too lazy to write. Find a better algorithm:
1. x-number
2. n=1,000,000,000
3.a="0"
4.x=x-n
5. if x<0 then goto 8
6. a=a+1
7. goto 4
8. store a ;save the next character.
9. n=n/10; instead of dividing, you can take the next number from the table
10. if n>0 then goto 3.
11. exit
The idea is this: we count how many in the number of billions, hundreds of millions, tens
millions, etc. to the number of units.
I wish you health, happiness and creative Uzbeks.
Aleksey Malov aka VIVID/Brainwave.