How do I get to convert this number 83726188455589 into a 48 bit binary number?

I have a problem trying to set the pins of the Arduino Mega 2560 so I can program the address pins & the data pins for setting the frequency of the DDS that I'm programming. It uses a 48 bit data space to store the number. First I have to convert it to binary (hence the 48 bit binary number) so I can individually set the pins to be stored in the data bits of each Data byte. So far I have this

void setFTW1( int Frequency1) {
	byte addresses [] = {0x04, 0x05, 0x06, 0x07, 0x08, 0x09};
	int FTW1 = (Frequency * power (2, 48)) / 300000000;
	foreach ( address in addresses ) {
        setAddress(address);
        setData(data);  <===== this is the problem

	}
}

FTW1 is the frequency Tuning Word and it needs to be in binary format.
This is C++ code for my library when I get done.
Thanks in advance for all your help.
Mel

What pins of the Mega 2560? Can you show us a wiring diagram?

Initialize a long long (64 bit) integer to the decimal number, and output the lower 48 bits (6 bytes).

The Arduino does not completely support long longs, so you may have to do it on another computer. Mind big and little endian.

Or, store the number as individual binary bits, and output them 8 at a time. This calculator will produce the binary representation.

That does not look like C++ code. power() function? foreach()?

I'd break the problem in two and have 2 24 bit values (unsigned long) and deal with each such that you end up with setData( dataUpper, dataLower );

_Others awk 'BEGIN { printf "%x\n", 83726188455589 }'
4c2605b8a6a5

Thanks Guys,

That's was quick, I got an error message from some one that I had to correct but could not see how to do that.

Shannon,

The pins are 23 - 33 for addresses and 24 - 38 for the data. But they are connected with a 36 pin connector to the DDS so it is a ribbon cable. Some of the other pins on the connector will be for other type of inputs and outputs.

jremington,

I like the long long suggestion as well. I sort of would like to keep it all together in the software. I have a function in excel that I've been trying to reproduce as well but it needed the long long that you suggested.

blh64 ,

Your right of course I'm 90% C# and having to do things in C++ is a challenge again.

gcjr,

Not sure how I'm going to get this into my code. This is what I'm looking for:

dec bin
83726188455589 10011000010011000000101101110001010011010100101

This code works correctly, so just use mask and shift to output 8 bits at a time.
Note: Serial.print() doesn't seem to understand long long.

void setup() {
long long x = 83726188455589LL;
Serial.begin(9600);
long y = x/65536LL; //top 32 of 48 bits.
Serial.println(y);  //prints 1277560248
y = x>>16;
Serial.println(y); //ditto
}

void loop() {}

With terrible waste of memory, you can store binary constants as a character string. The lowest order bit of the string is x[strlen(x)] and so on. Put the string in PROGMEM to save RAM, of course.

char x[]="10011000010011000000101101110001010011010100101";

If your data pins are 24-38, then you only need 15 bits

pamam:
The pins are 23 - 33 for addresses and 24 - 38 for the data.

That makes no sense unless you mean address are 23 - 33 ODD and data is 24-38 EVEN.

If that is the case, you don't have 48 data pins.

OK, I'm looking at this code which does not run as expected.

long long x;
int result;

void setup() {
Serial.begin(9600);
delay(5000);
}

void loop() {
x = 83726188455589LL;
for (int n = 48; n <= 0; n--)
{
result = bitRead(x, n);
Serial.print(result);
delay(1000);
Serial.print(result);
delay(1000);
}
Serial.println(result);

}

This code only prints out the last Serial.println; repeatedly.
When I use the prints in the for loop nothing prints out, with the exception of the println outside the for loop.

Can anyone tell me what I'm doing wrong?

(int n = 48; n <= 0; n--)Oops

Please remember to use code tags when posting code

  long long x;
  int result;

void setup() {
  Serial.begin(9600);
    x = 83726188455589LL;
  for (int n = 0; n<48; n++)
  {
    result = bitRead(x, 47-n);
    Serial.print(result);  //010011000010011000000101101110001010011010100101

  }
  Serial.println();
}

void loop() {}

jremington:

for (int n = 0; n<48; n++)

{

It is correct; but, it is not logical. The logical approach is what the OP has attempted (with a little bit of errors).

for (int n = 47; n>=0 ; n--)
  {

In English Language, we read/write from left to right; so, the OP wants to read the 47th bit (in binary count sequence) first and then display it. Therefore, the for() loop should logically begin with n=47 and not n=0?

It is correct; but, it is not logical.

Look at the rest of the code to understand why this is perfectly logical.

Thanks again for your help. I see that the conditional in the for loop is a while type not an until.
It's very much appreciated
pamam

pamam:
Shannon,

That's not my name. It's my forum membership class. You, for example, are called a Newbie (look under your picture).

aarg:
That's not my name. It's my forum membership class. You, for example, are called a Newbie (look under your picture).

Is it membership class or category? I see it changes. What is the criteria of such change? Alos (by-the-by) what does Karma signify?

Class.
Post count.
Very little.

Good (+K).

Sorry about that aarg. I saw with the others after I sent my post so I could not change kit anymore.

This problem has been answered and is now working just like I need it to. How do I formally close a p[ost.

Thanks,
pamam

Posts don't get closed. The idea is to leave the question and answer as it stands, in case someone else can learn from it. You could edit the thread title and add "Solved".