+ Post New Thread
Results 1 to 6 of 6
  1. #1
    Advanced Member level 1
    Points: 3,241, Level: 13

    Join Date
    Feb 2012
    Location
    Jeonju, South Korea
    Posts
    468
    Helped
    27 / 27
    Points
    3,241
    Level
    13

    concatenate memory locations in c++

    hi all

    I need to concatenate memory locations where data is in 'short' format, while I need to concatenate them to 64-bit (i.e. long formate) such that adjacent 16-bit data concatenate, i.e. if data is

    c6, 23, 12, F2 => (then it becomes) c62312F2

    please see the image below...

    I have tried few things but couldnot succeed

    I will be thankful

    Click image for larger version. 

Name:	IMG_5819.JPG 
Views:	6 
Size:	43.1 KB 
ID:	96788

    Bests,
    Shan
    When the going gets weird, the weird turn pro.
    H.S. Thompson

    •   AltAdvertisement

        
       

  2. #2
    Super Moderator
    Points: 260,224, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    45,442
    Helped
    13826 / 13826
    Points
    260,224
    Level
    100

    Re: concatenate memory locations in c++

    Just declare the memory as union of short and long long array, or use pointer type cast.



    •   AltAdvertisement

        
       

  3. #3
    Advanced Member level 1
    Points: 3,241, Level: 13

    Join Date
    Feb 2012
    Location
    Jeonju, South Korea
    Posts
    468
    Helped
    27 / 27
    Points
    3,241
    Level
    13

    Re: concatenate memory locations in c++

    Thank you for your response.

    Your method is also effective. But I also find one more methods, i.e. bit shifting and then doing or like one use to do in micro controller programming, here we are doing it for microprocessor and computer memory...

    so it is something like this as code below...But the thing is I cannot get 64-bit even when I use long long or __int64

    Code:
    ...
    __int64 long_temp = 0xfffffffffffffff;
    signed short int *sh_pbuff;
    ...
    ...
    sh_pbuff = (short int *)malloc(sizeof(short int)*12);
    
    for (int g = 0; g < 12; g ++)
    	*(sh_pbuff + g) = g*10 ;
    ....
    ...
    
    long_temp = (*(sh_pbuff + k + g) << 47) | (*(sh_pbuff + k + g) << 31) | (*(sh_pbuff + k + g) << 15) | (*(sh_pbuff + k + g) << 0);
    
    ...

    //but the thing is I am using visual studio 2010 for comiling and it is taking long_temp as 32 bit variable instaead of 64 bit..(this is evident with the results... I have)

    any idea..Doing so even if I use Union example I will face this same problem since I cannotutlize 64-bit data type

    Note that it is only a test code
    When the going gets weird, the weird turn pro.
    H.S. Thompson



    •   AltAdvertisement

        
       

  4. #4
    Super Moderator
    Points: 260,224, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    45,442
    Helped
    13826 / 13826
    Points
    260,224
    Level
    100

    Re: concatenate memory locations in c++

    Your latest post seems to confuse the problem. The initial post is talking about a 64-bit data bus. This suggests a 64-bit processor and a compiler supporting it, e.g. by a 64-bit data type, isn't it?

    It might be that you didn't explain the real problem, respectively I didn't understand it, but accessing a memory in 16 and 64-bit entities alternatively hasn't much to do with concatenation, I think.



  5. #5
    Advanced Member level 1
    Points: 3,241, Level: 13

    Join Date
    Feb 2012
    Location
    Jeonju, South Korea
    Posts
    468
    Helped
    27 / 27
    Points
    3,241
    Level
    13

    Re: concatenate memory locations in c++

    no no

    it does not matter if the processor is 64 bit or 32 bit...
    The DSP board I am using is PCIe based, hence no matter for 64 bit, it is 4 lane PCI-e and the data that I send in 64-bit format, (it seems) the API provided by the developers will transform it into first 64-bit, later they have a module which I have used that will give me output in 64-bit form...Hence actually naively speaking, this thing, i.e. data from C++ up untill I receive it after that module, is transparent to FPGA developers ( of course technically not)

    Hope this helps to understand...I have been trying to resolve for more than 1 day now...I dont want my design in FPGA since that will take too much time then.

    but accessing a memory in 16 and 64-bit entities alternatively hasn't much to do with concatenation, I think.
    please see the image that I have shown you...
    When the going gets weird, the weird turn pro.
    H.S. Thompson



    •   AltAdvertisement

        
       

  6. #6
    Super Moderator
    Points: 260,224, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    45,442
    Helped
    13826 / 13826
    Points
    260,224
    Level
    100

    Re: concatenate memory locations in c++

    Unfortunately I don't understand the problem at all. It seems like a basic programming thing.



--[[ ]]--