LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

using memcpy with different data types

hi,

i would like to copy DWORD(32bit) data buffer contents into a another buffer which is 64bit. i want to create one 64bit word out of two 32bit DWORDS and copy it into to one location of the 64bit buffer.

i have been trying to use memcpy but no success.

Thanks

0 Kudos
Message 1 of 4
(6,225 Views)

The memcpy function doesn't care about data types. It's arguments are a pointer to the source data, a pointer to the destination buffer, and how many bytes to copy.

 

If you have 2 DWORD variables representing the high and low order halves of a int64 and want to reconstitute the int64 then this something like this should work:

DWORD lowHalf;

DWORD highHalf;

__int64 myNewInt64;

 

myNewInt64 = ((__int64)highHalf << 32) | lowHalf;  // cast highHalf to __int64, then left shift it 32 bits, then bitwise or in the lowHalf

 

Michael

NI

 

0 Kudos
Message 2 of 4
(6,212 Views)

Hi,

This is the function i created U64 word form 2 Dwords. But it doesn't give me correct results. When i debugged the program it gives me incorrect values in U64 word array. Can somebody help me on this?

Thanks

 

 

void myFunction (U64 *pBuffer, U32 * oBuffer,U32 *nBuffer)
{
int k=0;
int j=0;
int i;

for (i=2; i<512; i++)
{
 pBuffer[i]=((U64)oBuffer[k] << 32) | ((U64)oBuffer[k+1]);

 k=k+2;
}
k=0;

for (i=0; i<64; i++)
 
 {
  nBuffer[0+j]= 0x00000000FFFFFFFF & (U32)pBuffer[0+k]; // does this assign LSB 32 bits of 64bit word? first word of 32bit bufffer
  
  nBuffer[1+j]= ((0x0000000F00000000 & pBuffer[0+k]) >> 32) | ((pBuffer[1+k] << 4 )& 0x00000000fffffff0); //second word of 32bit buffer
  
  nBuffer[2+j]= ((0x0000000FF0000000 & pBuffer[1+k]) >> 28) | ((pBuffer[2+k] << 😎 & 0x00000000ffffff00);
  
  nBuffer[3+j]= ((0x0000000FFF000000 & pBuffer[2+k]) >> 24) | ((pBuffer[3+k] << 12) & 0x00000000fffff000);
  
  nBuffer[4+j]= ((0x0000000FFFF00000 & pBuffer[3+k]) >> 20) | ((pBuffer[4+k] << 16) & 0x00000000ffff0000);
  
  nBuffer[5+j]= ((0x0000000FFFFF0000 & pBuffer[4+k]) >> 16) | ((pBuffer[5+k] << 20) & 0x00000000fff00000);
  
  nBuffer[6+j]= ((0x0000000FFFFFF000 & pBuffer[5+k]) >> 12) | ((pBuffer[6+k] << 24) & 0x00000000ff000000);
  
  nBuffer[7+j]= ((0x0000000FFFFFFF00 & pBuffer[6+k]) >> 😎 | (pBuffer[7+k]  & 0x000000000000000f);
  
  nBuffer[8+j]= pBuffer[7+k] >> 4;
  
  j=j+9;
  k=k+8;

 }
 
}

0 Kudos
Message 3 of 4
(6,167 Views)

Thanks. i was confusing myself. this code works.

 

0 Kudos
Message 4 of 4
(6,151 Views)