1. Moving data

Hey is there fast way to move data between different types?

I had in delphi function called move so i could do like this :

Code:
```a,b : Integer;
buff : array[0..3] of byte
....
move(a, buff[0], 4);
move(buff[0], b, 4);```
Is something like that in C++? I need to store integers and long ints into buffer which i need to send via TCP.

2. In C++, you just swap variable values.... Do you know the concept of swapping?

3. Hm, not really

Do you mean something like (type *) (void) (int) ?

4. No , like,
Code:
```int x=1;
int y=2;
int z=x;
x=y;
y=z;```
This is called swapping...

5. Originally Posted by Mr.777
No , like,
Code:
```int x=1;
int y=2;
int z=x;
x=y;
y=z;```
This is called swapping...
Ohh i know what you are talking about but, what swapping have to do with this

Code:
```unsigned long a;
BYTE myBuff[0xFFFF];
..
//How to place (a) into buffer starting from 20th pos, myBuff[20]
//So my number will be as hex in myBuff pos 20 to 24.```

As pointers directly refers to the memory addresses.
May be something like this....
Code:
```BYTE * ptr=myBuff[0];
ptr+=20;
*ptr=a;```

7. You could learn about bit manipulation and make an attempt that way. In particular shifting and AND are going to be useful. OTOH, memcpy will probably work too.

8. Instead of using memcpy, i'll recommend memmove........

9. Which one is correct? That later i everybody can read from buffer corectly not from behind?

Code:
```buff[3] = a;
buff[2] = a >> 8;
buff[1] = a >> 16;
buff[0] = a >> 24;```
Code:
```buff[3] = a >> 24;
buff[2] = a >> 16;
buff[1] = a >> 8;
buff[0] = a;```

10. I belive first one as you will shift to the number of bits after you get the value...
And the second one will shift you more far......
What do you say?

11. So i can shift like that whole string to buff increasing number of bits by 8 every time?

12. Yes, you can.....

13. What's wrong with this def?

Code:
`typedef BYTE[4] BLOCK;`

14. A typedef looks exactly the same as a variable declaration, except for the typedef keyword.

Code:
```BYTE block[4]; //block is an array

typedef BYTE block[4]; //block is another name for BYTE[4]```