Page 1 of 1

Missing subject Split Long integer 32bit or 64bit into Bytes

Posted: Thu May 20, 2010 4:34 pm
by Huib Koppers
Hello,

The C4AVR coarse handles Integer, but not "long integer" and "split long integer" variable for 32 or 64bit to 4 or 8 bytes funtions.
Also conversions from 32bit or 48bit to 9 or 10 digit decimal into 4 or 6 byte or string format explained into C is very usefull to me.

Maybe my subject question lays out of the level of this coarse and i can understand

But this is for me an important part which has become a lot of interrest for my DDS project.

Don't understand my wrong its a good coarse with very usefull information but was also espacially interrested in the split and long integer variants and my hope was finding it in C4AVR

There are some asm examples but i am also interrested in the C version to be explained.

I have googled about the subject but give me not the full explanation about syntacts build in C

Are there some books who handle the full explanation long integer and in combination with split functions ?

The reason about this is that i have DDS chips with 32bit and 48bit tuning words to make 1 Hz tunning possible.
The split function is needed to split the 32bit into 4 bytes to save to 8bit memory locations for EEprom and SPI port adressing.
Also conversion from 32bit to 9 digits decimal to save into 4byte or string format is an interresting and important subject for me

I hope you can help me

Kind Regards

Huib

Re: Missing subject Split Long integer 32bit or 64bit into B

Posted: Fri May 21, 2010 9:00 am
by Benj
Hello Huib,

Here is a quick example of a 32 bit variable and splitting it up into 4 bytes.

unsigned long var32;

var32 = 0xFFFFFFFF;

char bytes[4];

bytes[0] = var32 & 0xFF;
bytes[1] = (var32 >> 8 ) & 0xFF;
bytes[2] = (var32 >> 16) & 0xFF;
bytes[3] = (var32 >> 24) & 0xFF;

Not sure about 64-bit variables using GCC.

Re: Missing subject Split Long integer 32bit or 64bit into B

Posted: Fri May 21, 2010 9:06 am
by Benj
Converting a number into a string is quite easy. Ill show you a quick example.

idx = 0;
if (var >= 100)
{
string[idx] = (var / 100) + '0';
var = var % 100;
idx = idx + 1;
}
if (var >= 10)
{
string[idx] = (var / 10) + '0';
var = var % 10;
idx = idx + 1;
}

string[idx] = var + '0';
idx = idx + 1;

string[idx] = 0;

Re: Missing subject Split Long integer 32bit or 64bit into B

Posted: Tue May 25, 2010 6:47 am
by Huib Koppers
Hello Ben,

Thanks for your reply

On your conversion example I understand that it does also the compleet the decimal conversion to decimal numbers because of the weight calcs 10, 100 etc, etc.
I shall try this out

Kind Regards

Huib