Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

conversion hex to bcd

Status
Not open for further replies.

vicky29

Member level 4
Joined
Feb 5, 2005
Messages
75
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,288
Activity points
750
hex to bcd

hi people
can anybody help me out for how to convert a hexadecimal number into BCD format.for eg: i have a counter having count 504 .in hex it is 1F8h .now what will be its BCD code?
please help
thanks
 

bcd to hex

If 504 is the decimal, convert the 5 and the 0 and the 4 to four bit binary numbers and string them together. 0101 0000 0100 is the answer. Or without spaces 010100000100
 

hex to bcd conversion

hi

BCD code of every number is completely like decimal and does't depend
on hex fomat, it means that when you have the number 504 in decimal, it's BCD code has 4 bit for digit 4, 4 bit for digit 0 and 4 bit for the digit 5 ( and BCD has no digit more than 9), so in every 8 bit register, you have 2 BCD numbers, so your number will be
0000'0101 0000'0100

masoud
 

hexadecimal to bcd

Salam,


Hex2BCD Converter using 8051

Code:
;
;****************************************************************************
;
;  Description:
;	Convert Value In Acc From Hex To BCD.  
;
;  Entry Requirements:
;	Acc Has Value In Binary To Convert To BCD
;
;  On Exit:
;	Acc Has Entry Value Converted To BCD
;
;  Affected:
;	PSW.CY, PSW.Z, PSW.P, Acc
;
;  Stack:
;	1 Bytes, Not Including Space Used By Called Routines
;
;  Comments:
;	Values Greater Than 99 Will Not Work Properly.
;
;****************************************************************************


UTIL_BINTOBCD	proc
		push	b			; Save B
		mov	b,#10			; Divide By 10
		div	ab			; Do Divide
		swap	a			; Move Result To High Of A
		orl	a,b			; OR In Remainder
		pop	b			; Recover B
		ret				; Return To Caller
		endproc

SphinX
 

hex to bcd converter

thanks for replying but if i have a 16bit value or a 32 bit value in that case how will the code be written with 8051 microcontroller. cause the value in the programming will be hexadecimal .suppose the value in hex is 2ED(h) then how to convert this to BCD form.
 

convert hex to bcd

Salam,

You will find a code here



in PIC but you can convert it to 8051 becuase it use simple Bitwise instructions

Bye
 

bcd to hex conversion

garg29 said:
suppose the value in hex is 2ED(h) then how to convert this to BCD form.
It would be much easier if you first convert it to decimal format and then write the binary code for each digfit of the number e..g. for 2ED(h), the decimal equivalent would be 749 and the resulting BCD code would be 0111 0100 1001.
 

in that program 16 bit hex convert to bcd. I dont know the algorithm exactly but the result is right every time.if you have any problem you can ask me...
 

    V

    Points: 2
    Helpful Answer Positive Rating
sorry wrong post i got entered in....
 

It seems that lot of people have problem with BCD.

BCD stands for Binary Coded Decimal. As we all know decimal numbers have range from 0 to 9, thanslated to binary it is 0b0000 to 0b1001. As the decimal digit occupies no more than 4 bits any 8 bit variable (or register) can contain TWO decimal digits in it's two 4-bit chunks called nibbles.

If you take some datasheets for RTC chips, that's the way of keeping Hours, Minutes, Secinds in only 3 bytes.

HTH
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top