electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

A problem with Binary to BCD conversion in C


Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> A problem with Binary to BCD conversion in C
Author Message
Tulipmania



Joined: 06 Jan 2006
Posts: 6


Post06 Jan 2006 18:53   

A problem with Binary to BCD conversion in C


Hi,
I need help with this module . It's to convert a binary value to its BCD equivalent assigning each digit to an element of an array. For example the binary value (11111111=ff hex) is equivalent to( 255 ) decimal so the 5 digit is assigned to the first element of the array......second 5 is assigned to the next element and 2 is assigned to the third. the problem is that the module is able to assign only the first two digits and never gets to assign the third digit to the third element of the array.
I noted that while simulating the module..so what's wrong with it ?

the program;

#include<reg52.h>


void main (void)
{
int x; //Array Index
unsigned int binvalue=0x00ff; // Binary value to be converted & displayed
int INT_DIGITS[3]; // Declaration of Array of digits separated
int *INT_PTR; // Array Pointer

x=0; //Initializing the pointer to point the first element

do
{
INT_PTR = &INT_DIGITS[x];// set INT_PTR to point to indexed element in INT_DIGITS
*INT_PTR= (binvalue%10); // Assigning the ASCII value to the element
binvalue = binvalue/10;
++x;
}
while(binvalue >= 10);
}
Back to top
Google
AdSense
Google Adsense




Post06 Jan 2006 18:53   

Ads




Back to top
echo47



Joined: 07 Apr 2002
Posts: 4206
Helped: 566


Post06 Jan 2006 19:44   

A problem with Binary to BCD conversion in C


Your "do" loop executes twice, not three times. Look at what's happening in the "while" test.
Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> A problem with Binary to BCD conversion in C
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
Binary to BCD (3)
hexkeyboard to BCD/Binary (8)
Binary to BCD question (3)
binary to bcd converter (3)
10 Bit Binary to 4 Digit BCD???????? (4)
Convert 26 bit binary to BCD Routine (1)
8 bits binary no. to BCD by using VHDL. (2)
want converter chip from binary to bcd (7)
how to convert binary to BCD or decimal in assembly (4)
Whats the easiest way to convert Binary to BCD (8)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS