+ Post New Thread
Results 1 to 10 of 10

5th February 2005, 05:36 #1
 Join Date
 Feb 2005
 Posts
 75
 Helped
 3 / 3
 Points
 2,549
 Level
 11
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

5th February 2005, 05:36

5th February 2005, 05:54 #2
 Join Date
 Jul 2002
 Location
 Middle Earth
 Posts
 4,629
 Helped
 491 / 491
 Points
 36,491
 Level
 46
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

5th February 2005, 06:26 #3
 Join Date
 Jan 2005
 Posts
 28
 Helped
 4 / 4
 Points
 1,696
 Level
 9
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

5th February 2005, 12:12 #4
 Join Date
 Jan 2002
 Location
 EGYPT
 Posts
 822
 Helped
 59 / 59
 Points
 6,852
 Level
 19
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

5th February 2005, 12:12

5th February 2005, 13:51 #5
 Join Date
 Nov 2004
 Posts
 451
 Helped
 25 / 25
 Points
 4,355
 Level
 15
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.

5th February 2005, 14:48 #6
 Join Date
 Jan 2002
 Location
 EGYPT
 Posts
 822
 Helped
 59 / 59
 Points
 6,852
 Level
 19
convert hex to bcd
Salam,
You will find a code here
http://www.piclist.com/techref/micro...adix/index.htm
in PIC but you can convert it to 8051 becuase it use simple Bitwise instructions
Bye

7th February 2005, 19:17 #7
 Join Date
 Feb 2005
 Posts
 37
 Helped
 1 / 1
 Points
 1,666
 Level
 9
bcd to hex conversion
Originally Posted by garg29

22nd November 2009, 14:07 #8
 Join Date
 May 2009
 Location
 turkey
 Posts
 7
 Helped
 1 / 1
 Points
 751
 Level
 6
Re: conversion hex to bcd
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...
1 members found this post helpful.

4th February 2010, 15:12 #9
 Join Date
 May 2009
 Posts
 37
 Helped
 0 / 0
 Points
 1,147
 Level
 7
Re: conversion hex to bcd
sorry wrong post i got entered in....

4th February 2010, 15:12

4th February 2010, 20:51 #10
 Join Date
 Jan 2008
 Location
 Messy Corner, 44°47'31.56"N, 20°28'9.16"E
 Posts
 533
 Helped
 109 / 109
 Points
 4,409
 Level
 15
conversion hex to bcd
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 4bit chunks called nibbles.
If you take some datasheets for RTC chips, that's the way of keeping Hours, Minutes, Secinds in only 3 bytes.
HTHMake no mistake between my personality and my attitude.
My personality is who I am.
My attitude depends on who you are.
+ Post New Thread
Please login