Long number

Hi,

I need to transmit data using 433 MHz wireless module and actually I need to send a 64 bits number. I know I cant store a variable this size inside arduino cause the larger number I can store must have 32 bits.

So how can I store a 64 bits variable? Can I create a byte variable to save the 64 0's and 1's?

I cant make smaller transfers of 8 bits, I need to send the 64 bits at once.

Actually what I want to do is this: I have 8 different numbers with 8 bits each in one arduino and I want to transfer it to another arduino. I thought about concating the 8 bits of each number and make a 64 bit number to transfer it only once.

For example, if one number is 00010001 and the other is 11001100 my final number would be:

0001000111001100

Is there another better way to join 2 numbers without concating the bits?

Thakn you so much!

I know I cant store a variable this size inside arduino cause the larger number I can store must have 32 bits

You’re wrong.
Try “unsigned long long”

Is there another better way to join 2 numbers without concating the bits?

No.

That's silly. There's no difference. If you have 8 8bit variables, then send them out one by one all in a row. If you did have them in a 64bit data type, they'd get broken back up into 8bit bytes to get sent out anyway. So there's no difference except for wasted code and wasted spece for this 64bit data buffer.

gilperon:
delta_g you are so wrong. If I send 8 bit at every time there is a huge overhead cause the protocol I am using in the comunication. That's why I need to send 64 bits at a time to make sure the overhead will only be generated once.

You only get to send 8 bits at a time. If you send a 64 bit number, then some function somewhere is going to have to break it down to send it out. Go have a look at the source for Print and see how it handles ints and longs. Which function you do the breakdown in makes no difference. Just because you only see one line in your code doesn't mean the overhead is any less. That one line calls a function and that function sees the overhead. It's still there no matter which function you put it in. Sending out 64 bits is sending out 64 bits no matter how you stack it.

Your way actually has more overhead because you add the code to combine them and break them back down.

Have a look at section 20 of the datasheet for the 328 and tell me where this 64 bit number is going to go all at once.

Delta_G:
Go have a look at the source for Print and see how it handles ints and longs.

I'm sorry, not Print. HardwareSerial has an example. If you try to write an int or a long it just truncates it to 8bits. If you want to put out an int or a long you have to cast them to an array of bytes and give them to write(buf, size).

    inline size_t write(unsigned long n) { return write((uint8_t)n); }
    inline size_t write(long n) { return write((uint8_t)n); }
    inline size_t write(unsigned int n) { return write((uint8_t)n); }
    inline size_t write(int n) { return write((uint8_t)n); }
    using Print::write; // pull in write(str) and write(buf, size) from Print

Notice it pulls in write methods from Print. Let's look at those.

size_t Print::write(const uint8_t *buffer, size_t size)
{
  size_t n = 0;
  while (size--) {
    n += write(*buffer++);
  }
  return n;
}

There it is, getting broken into bytes to send out one at a time. On an 8 bit machine that's pretty much the only way it's ever going to happen.

gilperon:
delta_g you are so wrong.

No he is so right, it is you that is wrong.

The shift operation >> is coupled with the bitwise inclusive OR operation | to combine bytes into longer variable types.