C program for converting 24-bit BIN to BCD format

Status
Not open for further replies.

Alexander Prad

Junior Member level 1
Joined
May 11, 2003
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Odessa, Ukraine
Activity points
182
Hi!
Anyone saw in web a c-program for converting 24-bit BIN to BCD format?
Thank you.
Alexander.
 

24bit to bcd

Good man Epegic give me a good solution.
here is it:

void binaryToBCD(long unsigned binaryNumber)
{
unsigned char index;
for (index=0; index<numberofDigits; index++)
{
if (binaryNumber!=0)
{
bcdNumber[index] = binaryNumber%10;
binaryNumber = binaryNumber/10;
}
}
}
 

bin2bcd algorithm

Thanks a lot for your good code
I don't want to use add-3 algorithm for this conversion.
Thanks again.
 

include bin2bcd

for something inline....

#include <math.h>
#include <stdio.h>

int y,x,z,bits,bit,array;
bits =24;
array=0; {bitvalue 3rd dimention position {super position}}
LONG bitvalue[array];

bitvalue = convertion input value

BOOL fifo[bits];
x=1;
z=1; {can be used to choose what bit to address like a rom you just update changed bits only}

for(y=0;y<=bits
{
(fifo[bit])? bitvalue[array] |= (x) : bitvalue[array] &= ~(x); //bitvalue can be an array
x=x+x;
bit=bit+z;
y++;
}



i see a mistake here not so easy to fix

ill think more on this



you can enclose the whole object in a void routine if you like
gives more variables also to break the scope of use out a little
void'd routines are cool but inline is better
something along this lines is maybe usefull as a converter buffer
even adding a convertion mode is easier
choice is there also to do group block convertions
ie if you need 8 bit result then only do 8 bit convertions with no padding
or you can build a 3d array like ram

using a constructor like
bit = 24;
bits =24;

long[bit][bits];
to give 24 by 24 bit by 24 bit 3d dimention array
give result tables using convertion explode functions
its actualy faster in pentium to calculate more results at once than lots of little groups
then just point to the start of your group and leech it off

you can also use two arrays inside each other
to strobe the result and actual convertion sequence
to your needs

attached is a little console type app
i use this method to perfect little maths functions
the test this does is
write 4 bytes to two dwords then to a long
then the long back to the bytes
then generate a random number
i think this method maybe best for you to use
to makeup and tailor to your exact needs
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…