# Free Electronic Circuits & 8085 projects

## HEX to Decimal conversion

Published on Nov 18 2009

Statement: Convert the HEX number in memory to its equivalent decimal number

 Source program : LXI H, 4150 ; Point to data LXI B, 0000 ; Initialize hundreds= 0, Tens=0 MOV A, M ; Get hex data to A LOOP: SUI 64 JC LOOP 1 INR B ; hundreds= hundreds+1 JMP LOOP LOOP 1: ADI 64 ; if subtracted extra, add it clear carry flag LOOP 2: SUI 0A   JC LOOP 3   INR C ; Tens=tens+1   JMP LOOP 2 LOOP 3: ADI 0A ; If subtracted extra, add it again INX H ; A = Units MOV M, B ; store hundreds MOV B, A ; Combine Tens in C & MOV A, C ; Units in A to form a RLC ; Single 8-bit number RLC RLC RLC ADD B INX H MOV M, A ; Store tens & Units HLT

Note: In this experiment the number is converted to its equivalent decimal number using the following logic.  First count the number of hundreds, the number of tens & units present in that hex number.  Then add up to get the equivalent decimal number.

Converting A9 we get:

A9 /64=45 Hundreds = 01

Since 64(100 decimal) cannot be subtracted from 45 no. of hundreds = 01.  Now count tens 45/0A=3B Tens = 01 Now from 09, 0A cannot be subtracted.  Hence tens = 06 the decimal equivalent of A9 is 169.

Related Programs for Beginners: (Click down)