Jul 29, 2014 #1 R raman00084 Full Member level 6 Joined Nov 29, 2010 Messages 362 Helped 2 Reputation 4 Reaction score 2 Trophy points 1,298 Activity points 4,006 please send sample program for bcd to decimal conversion in c i am using pic16f877a ccs complier
Jul 29, 2014 #2 M milan.rajik Banned Joined Apr 1, 2013 Messages 2,524 Helped 540 Reputation 1,078 Reaction score 524 Trophy points 1,393 Activity points 0 In two digit BCD say 23 is written as 0010 0011. So, to convert it to decimal you have to do something like this Code C - [expand]1 decNum = ((bcdNum >> 4) * 10) + (bcdNum & 0b00001111) 23 is a byte (upto 255 is a byte) BCD 23 will be stored as 00100011 00100011 >> 4 = 00000010 = 2 decimal 2 * 10 = 20 decimal 00100011 & 0b00001111 = 00000011 = 3 20 + 3 = 23 decimal
In two digit BCD say 23 is written as 0010 0011. So, to convert it to decimal you have to do something like this Code C - [expand]1 decNum = ((bcdNum >> 4) * 10) + (bcdNum & 0b00001111) 23 is a byte (upto 255 is a byte) BCD 23 will be stored as 00100011 00100011 >> 4 = 00000010 = 2 decimal 2 * 10 = 20 decimal 00100011 & 0b00001111 = 00000011 = 3 20 + 3 = 23 decimal
Jul 29, 2014 #3 Raady Here Full Member level 5 Joined Jun 8, 2013 Messages 242 Helped 26 Reputation 52 Reaction score 26 Trophy points 28 Location India Activity points 1,571 for variable unsigned char data perform ((((data & 0xF0 )>>4) * 10) + (data&0xF));
Jul 29, 2014 #4 M milan.rajik Banned Joined Apr 1, 2013 Messages 2,524 Helped 540 Reputation 1,078 Reaction score 524 Trophy points 1,393 Activity points 0 @Raady ((data & 0xF0) >> 4) is same as (data >> 4)
Jul 29, 2014 #5 G Gorgon Full Member level 6 Joined Nov 10, 2005 Messages 345 Helped 75 Reputation 150 Reaction score 67 Trophy points 1,308 Location Norway Activity points 3,787 milan.rajik said: @Raady ((data & 0xF0) >> 4) is same as (data >> 4) Click to expand... Only as long as 'data' is a char. If it is an integer it may be the same.
milan.rajik said: @Raady ((data & 0xF0) >> 4) is same as (data >> 4) Click to expand... Only as long as 'data' is a char. If it is an integer it may be the same.