Both the arrays contain 1750 characters each and the difference needs to be stored in third array.

Before expecting any comments from us, please show us what you have done yourself. Did you think about it atall? If yes.. what are your thoughts? If no... think about it first.

Also what exactly do you mean by difference? Do you mean the ASCII number difference... or do you mean the third array is an array of bools. so the third array would be thirdArray[x] = 0 if firstArray[x] and secondArray[x] are the same and thirdArray[x] = 1 if firstArray[x] and secondArray[x] are different.

There are all kinds of things you can do for the "difference" but you need to give us more info and proof that you've even attempted the problem before you get help from us

Yes what does difference mean in your case ?

difference1 : 4 - 3 = 1
difference2 : {a,b,c} - {a,d,f} = {b,c}

is repitition of 125 bitsx100 for 100 aircraft tracks as latitude longitude heading spees etc each one varying from other also has 8 messages of 12 ASCII characters each at the end of both the arrays ,currently i am generating this data randomly and my purpose is to compress the amount of data that would be transmitted.
I have chosen to transmit the radar data which i have described earlier ,differentially.

So basically you need the Arithmetic difference of both arrays, something like this:

int* getDiff(int *arr1, int *arr2)
{
  int maxCount = 1750; //From your 1st Post
  int *result = new [maxCount];
  for(int i=0 ; i<maxCount ; i++ )
    result[i]=arr1[i]-arr2[i];
  return result;   
}

So basically you need the Arithmetic difference of both arrays, something like this:

int* getDiff(int *arr1, int *arr2)
{
  int maxCount = 1750; //From your 1st Post
  int *result = new [maxCount];
  for(int i=0 ; i<maxCount ; i++ )
    result[i]=arr1[i]-arr2[i];
  return result;   
}

Ouch, thats pretty bad. I would have just used stl,

#include <algorithm>
#include <functional>
#include <vector>
using namespace std;
int main(){
 //std::vector is better, just using arrays for demonstration
 const int SZ = 5;
 int a1[SZ] = {1,2,3,4,5};
 int a2[SZ] = {5,4,3,2,1};
 int res[SZ] = {0};
 std::transform(a1,a1+SZ,a2,res,std::minus<int>());
 
}

So basically you need the Arithmetic difference of both arrays, something like this:

int* getDiff(int *arr1, int *arr2)
{
  int maxCount = 1750; //From your 1st Post
  int *result = new [maxCount];
  for(int i=0 ; i<maxCount ; i++ )
    result[i]=arr1[i]-arr2[i];
  return result;   
}

#include<iostream>
#include"DLP_Functions1.h"
#include<stdlib.h>
#include<iomanip>
void generate_RADAR_data_make_trasmit_file(void);
unsigned long id,type,altitude,heading,speed;
double latitude,longitude;
long sequence_number= 0;
unsigned char radar_picture_array[1750];              // SAME ARRAY BEING USED FOR TX RX
int main()
{











}
void generate_RADAR_data_make_trasmit_file(void)
{
         static int tx_frame_number = 0;
        if(sequence_number ==0)
        {
        unsigned char m1[13]="MessageCont1";
        unsigned char m2[13]="MessageCont2";
        unsigned char m3[13]="MessageCont3";
        unsigned char m4[13]="MessageCont4";
        unsigned char m5[13]="MessageCont5";
        unsigned char m6[13]="MessageCont6";
        unsigned char m7[13]="MessageCont7";
        unsigned char m8[13]="MessageCont8";

        for (int j=0;j<=99;j++)
        {
        type=(rand()+tx_frame_number)%250;
        id =(rand()+tx_frame_number*1000000)%9999;
        latitude=(rand()+tx_frame_number*1000000)%18099;
        longitude=(rand()+tx_frame_number*1000000)%36099;
        altitude=(rand()+tx_frame_number*1000000)%65536;
        heading=(rand()+tx_frame_number*1000000)%360;
        speed=(rand()+tx_frame_number*1000000)%2048;

        //////////static bit level encoding to make "radar_picture_array" from target parameters//////////////////
        value_to_array (radar_picture_array,(0+(j*125)),(1+(j*125)),type);
        value_to_array (radar_picture_array,(2+(j*125)),(57+(j*125)),id);
        value_to_array (radar_picture_array,(58+(j*125)),(72+(j*125)),latitude);
        value_to_array (radar_picture_array,(73+(j*125)),(88+(j*125)),longitude);
        value_to_array (radar_picture_array,(89+(j*125)),(104+(j*125)),altitude);
        value_to_array (radar_picture_array,(105+(j*125)),(113+(j*125)),heading);
        value_to_array (radar_picture_array,(114+(j*125)),(124+(j*125)),speed);

        if(j==99) // encoding command and control messages
        {
            for (int k=0;k<=11;k++)  array_to_array (radar_picture_array,(125+(j*125)+k*8),(132+(j*125)+k*8),m1,0+k*8,7+k*8);
            for (int k=0;k<=11;k++) array_to_array (radar_picture_array,(221+(j*125)+k*8),(228+(j*125)+k*8),m2,0+k*8,7+k*8);
            for (int k=0;k<=11;k++) array_to_array (radar_picture_array,(317+(j*125)+k*8),(324+(j*125)+k*8),m3,0+k*8,7+k*8);
            for (int k=0;k<=11;k++) array_to_array (radar_picture_array,(413+(j*125)+k*8),(420+(j*125)+k*8),m4,0+k*8,7+k*8);
            for (int k=0;k<=11;k++) array_to_array (radar_picture_array,(509+(j*125)+k*8),(516+(j*125)+k*8),m5,0+k*8,7+k*8);
            for (int k=0;k<=11;k++) array_to_array (radar_picture_array,(605+(j*125)+k*8),(612+(j*125)+k*8),m6,0+k*8,7+k*8);
            for (int k=0;k<=11;k++) array_to_array (radar_picture_array,(701+(j*125)+k*8),(708+(j*125)+k*8),m7,0+k*8,7+k*8);
            for (int k=0;k<=11;k++) array_to_array (radar_picture_array,(797+(j*125)+k*8),(804+(j*125)+k*8),m8,0+k*8,7+k*8);


        }
      }
      }

      }
      ///////////////////////////////////////FUNCTION DEFINITIONS//////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////


 ///////////////////////////function "value_to_array" definition////////////////

void value_to_array (unsigned char* ch,int from,int to,int value)
{
unsigned long a=1,b=0;
unsigned long bytenum,bitnum;
unsigned char setting[8]={128,64,32,16,8,4,2,1};
unsigned char clearing[8]={127,191,223,239,247,251,253,254};
    for(int x=to;x>=from;x--)
    {
   bytenum=x/8;
   bitnum =x%8;
   b=value&a;
        if(b==a)
    ch[bytenum]|= setting[bitnum];
      else
      ch[bytenum]&= clearing[bitnum];
      a=a<<1;
   }
}

 ///////////////////////////function "array_to_array" definition////////////////////
 ////////////////// this function can pick only 4 bytes at a time///////////////////

void array_to_array (unsigned char* ch1,int from1,int to1,unsigned char* ch2,int from2,int to2)
{
unsigned long a=1,b=0;
unsigned long bytenum,bitnum;
unsigned char setting[8]={128,64,32,16,8,4,2,1};
unsigned char clearing[8]={127,191,223,239,247,251,253,254};
unsigned long value=0;

    for(int x=from2;x<=to2;x++)
    {
    value*=2;
    bytenum=x/8;
    bitnum=x%8;
    b=ch2[bytenum]&setting[bitnum];
    if(b!=0)
    value+=1;
    }

    for(int x=to1;x>=from1;x--)
    {
   bytenum=x/8;
   bitnum =x%8;
   b=value&a;
        if(b==a)
        ch1[bytenum]|= setting[bitnum];
      else
      ch1[bytenum]&= clearing[bitnum];
      a=a<<1;
   }
}
//DLP_Functions1.h as follows
void value_to_array (unsigned char* ch,int from,int to,int value);  // maps a value onto an array
 void array_to_array (unsigned char* ch1,int from1,int to1,unsigned char* ch2,int from2,int to2);   // copies part of array to another array

end quote.

Thanks for your help;
But i have a question...
now what i am currently trying to do is to transmit difference of radar_picture_array and radar_picture_array_old_transmitted which will be filled/mapped with values,strings once first radar_picture_array will be transmitted completely,also at reciever side radar_picture_array_recieved will be added to radar_picture_array_recieved_old to recover the original array that was transmitted.

But i have a question...
now what i am currently trying to do is to transmit difference of radar_picture_array and radar_picture_array_old_transmitted which will be filled/mapped with values,strings once first radar_picture_array will be transmitted completely,also at reciever side radar_picture_array_recieved will be added to radar_picture_array_recieved_old to recover the original array that was transmitted.

And what is your question??? You just explained what you are doing but no question in it?

#include<iostream>
#include"DLP_Functions1.h"
#include<stdlib.h>
#include<iomanip>
void generate_RADAR_data_make_trasmit_file(void);
unsigned long id,type,altitude,heading,speed;
double latitude,longitude;
long sequence_number= 0;
unsigned char radar_picture_array[1750]; 
unsigned char radar_picture_array_old_transmitted[1750]; //will contain values of radar_picture_array transmitted last time
unsigned char radar_picture_array_diff[1750]; //unsigned char radar_picture_array[1750]-unsigned char radar_picture_array_old_transmitted[1750]
int main()
{











}
void generate_RADAR_data_make_trasmit_file(void)
{
static int tx_frame_number = 0;
if(sequence_number ==0)
{
unsigned char m1[13]="MessageCont1";
unsigned char m2[13]="MessageCont2";
unsigned char m3[13]="MessageCont3";
unsigned char m4[13]="MessageCont4";
unsigned char m5[13]="MessageCont5";
unsigned char m6[13]="MessageCont6";
unsigned char m7[13]="MessageCont7";
unsigned char m8[13]="MessageCont8";

for (int j=0;j<=99;j++)
{
type=(rand()+tx_frame_number)%250;
id =(rand()+tx_frame_number*1000000)%9999;
latitude=(rand()+tx_frame_number*1000000)%18099;
longitude=(rand()+tx_frame_number*1000000)%36099;
altitude=(rand()+tx_frame_number*1000000)%65536;
heading=(rand()+tx_frame_number*1000000)%360;
speed=(rand()+tx_frame_number*1000000)%2048;

//////////static bit level encoding to make "radar_picture_array" from target parameters//////////////////
value_to_array (radar_picture_array,(0+(j*125)),(1+(j*125)),type);
value_to_array (radar_picture_array,(2+(j*125)),(57+(j*125)),id);
value_to_array (radar_picture_array,(58+(j*125)),(72+(j*125)),latitude);
value_to_array (radar_picture_array,(73+(j*125)),(88+(j*125)),longitude);
value_to_array (radar_picture_array,(89+(j*125)),(104+(j*125)),altitude);
value_to_array (radar_picture_array,(105+(j*125)),(113+(j*125)),heading);
value_to_array (radar_picture_array,(114+(j*125)),(124+(j*125)),speed);

if(j==99) // encoding command and control messages
{
for (int k=0;k<=11;k++) array_to_array (radar_picture_array,(125+(j*125)+k*8),(132+(j*125)+k*8),m1,0+k*8,7+k*8);
for (int k=0;k<=11;k++) array_to_array (radar_picture_array,(221+(j*125)+k*8),(228+(j*125)+k*8),m2,0+k*8,7+k*8);
for (int k=0;k<=11;k++) array_to_array (radar_picture_array,(317+(j*125)+k*8),(324+(j*125)+k*8),m3,0+k*8,7+k*8);
for (int k=0;k<=11;k++) array_to_array (radar_picture_array,(413+(j*125)+k*8),(420+(j*125)+k*8),m4,0+k*8,7+k*8);
for (int k=0;k<=11;k++) array_to_array (radar_picture_array,(509+(j*125)+k*8),(516+(j*125)+k*8),m5,0+k*8,7+k*8);
for (int k=0;k<=11;k++) array_to_array (radar_picture_array,(605+(j*125)+k*8),(612+(j*125)+k*8),m6,0+k*8,7+k*8);
for (int k=0;k<=11;k++) array_to_array (radar_picture_array,(701+(j*125)+k*8),(708+(j*125)+k*8),m7,0+k*8,7+k*8);
for (int k=0;k<=11;k++) array_to_array (radar_picture_array,(797+(j*125)+k*8),(804+(j*125)+k*8),m8,0+k*8,7+k*8);


}
}
}

}
///////////////////////////////////////FUNCTION DEFINITIONS//////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////


///////////////////////////function "value_to_array" definition////////////////

void value_to_array (unsigned char* ch,int from,int to,int value)
{
unsigned long a=1,b=0;
unsigned long bytenum,bitnum;
unsigned char setting[8]={128,64,32,16,8,4,2,1};
unsigned char clearing[8]={127,191,223,239,247,251,253,254};
for(int x=to;x>=from;x--)
{
bytenum=x/8;
bitnum =x%8;
b=value&a;
if(b==a)
ch[bytenum]|= setting[bitnum];
else
ch[bytenum]&= clearing[bitnum];
a=a<<1;
}
}

///////////////////////////function "array_to_array" definition////////////////////
////////////////// this function can pick only 4 bytes at a time///////////////////

void array_to_array (unsigned char* ch1,int from1,int to1,unsigned char* ch2,int from2,int to2)
{
unsigned long a=1,b=0;
unsigned long bytenum,bitnum;
unsigned char setting[8]={128,64,32,16,8,4,2,1};
unsigned char clearing[8]={127,191,223,239,247,251,253,254};
unsigned long value=0;

for(int x=from2;x<=to2;x++)
{
value*=2;
bytenum=x/8;
bitnum=x%8;
b=ch2[bytenum]&setting[bitnum];
if(b!=0)
value+=1;
}

for(int x=to1;x>=from1;x--)
{
bytenum=x/8;
bitnum =x%8;
b=value&a;
if(b==a)
ch1[bytenum]|= setting[bitnum];
else
ch1[bytenum]&= clearing[bitnum];
a=a<<1;
}
}
//DLP_Functions1.h as follows
void value_to_array (unsigned char* ch,int from,int to,int value); // maps a value onto an array
void array_to_array (unsigned char* ch1,int from1,int to1,unsigned char* ch2,int from2,int to2); // copies part of array to another array

Question1. How to take difference of the arrays i mentioned above and once difference is taken then putting it into diff array
Questio2. Data is currently being generated randomly,but differential compression is more effective on sequential data what i mean to say is that aircraft perimeter like altitude cant change from 50,000 ft to 2000 ft in 4 sec because 4 sec is refresh time required in my case so
i have generated data randomly and sequential variations in MATLAB but need to translate in C++
HOPE U UNDERSTAND]

function data=generate_data(number_of_targets,readings)
    data=[];
    for n=1:number_of_targets
        ttype=round(rand*3);
        trackid=[round(rand*255) round(rand*255) round(rand*255) round(rand*255) round(rand*255) round(rand*255) round(rand*255)];
        lat=((-1)^(round(rand*3)))*round(rand*90);
        lon=((-1)^(round(rand*3)))*round(rand*180);
        alt=round(rand*65535);
        heading=round(rand*360);
        speed=round(rand*2000);
        tgt=[ttype trackid lat lon alt heading speed];
        data=[data;tgt];
    end
    for n=2:readings
        for m=1:number_of_targets
            latinc=(((-1)^(round(rand*3)))*round(rand*5))/100;
            loninc=(((-1)^(round(rand*3)))*round(rand*5))/100;
            altinc=(((-1)^(round(rand*3)))*round(rand*1000));
            speedinc=(((-1)^(round(rand*3)))*round(rand*350));
            data(m,1,n)=data(m,1,n-1);%ttype remains same
            data(m,2:8,n)=data(m,2:8,n-1);%tid remains same
            lat=data(m,9,n-1)+latinc;
            if lat<=90 && lat>=-90
                data(m,9,n)=lat;
            else
                data(m,9,n)=data(m,9,n-1);
            end
            lon=data(m,10,n-1)+loninc;
            if lon<=180 && lon>=-180
                data(m,10,n)=lon;
            else
                data(m,10,n)=data(m,10,n-1);
            end
            alt=data(m,11,n-1)+altinc;
            if alt<=65535
                data(m,11,n)=alt;
            else
                data(m,11,n)=data(m,11,n-1);
            end
            data(m,12,n)=round(rand*360);%heading
            speed=data(m,13,n-1)+speedinc;
            if speed<=2000
                data(m,13,n)=speed;
            else
                data(m,13,n)=data(m,13,n-1);
            end
        end
    end
end
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.