How to use bitwise exclusive-OR command in NSIS - nsis

Does anyone know how to perform a bitwise exclusive-OR command in NSIS?
The following is a C# code I would like to implement in NSIS:
private string CalculateChecksum(byte[] dataToCalculate)
{ int intChecksum1 = 0;
int intChecksum2 = 0;
if(strBase64ChrsArray== null)
{
strBase64ChrsArray = strBase64Chrs.Split(' ');
}
for (int i = 0; i < dataToCalculate.Length - 3; i++)
{
intChecksum1 ^= dataToCalculate[i];
}
for (int i = 1; i < dataToCalculate.Length - 2; i++)
{
intChecksum2 ^= dataToCalculate[i];
}
return strBase64ChrsArray.ElementAt((byte)intChecksum1) + strBase64ChrsArray.ElementAt((byte)intChecksum2);
}

IntOp $0 1234 ^ 5678
DetailPrint $0

Related

Select in loop - work all the time - linux

I got next question about select:
How to make select in loop ?
I try to do like that:
struct timeval timeout;
int sel;
size_t rozmiar = sizeof(pid_t);
char buf[rozmiar];
int i;
FD_ZERO(&set);
for(i = 0; i< val; i++)
{ FD_SET(fd[i][0], &set); // val -> N pipe2
}
timeout.tv_sec = 2;
timeout.tv_usec = 0;
while(1)
{
sel = select(val+1,&set,NULL,NULL,&timeout);
if(sel < 0)
perror("select");
else if(sel == 0)
printf("No communicate \n");
else{
for(i = 0; i < val; i++)
{
if(FD_ISSET(fd[i][0],&set))
{
while(read(fd[i][0],&buf,rozmiar) > 0)
write(1,&buf,rozmiar);
} // check if exist and write to stdout
}
} // end SELECT
timeout.tv_sec = 2;
timeout.tv_usec = 0;
}
But there all the time show: ,, no communicate". Is it the correct way to create select which work all the time? I am not sure so I prefer to ask. I try to find information in books but with no lucky.
The set is changed by select, you need to refill it each time

how can I display unsigned char with SetWindowText

I want to display unsigned char value with SetWindowText, but nothing displayed on label
code
DWORD WINAPI fill_matrix(LPVOID lpParameter)
{
unsigned char a = 'h';
for (int i = 0; i < 8; i++){
for (int j = 0; j <8; j++)
{
SetWindowText(hWndLabel[i * 8 + j], (LPCTSTR)a);
}
}
return 0;
}
I configured my project proprieties with unicode
SetWindowText requires string, not a single charater.
You should use SetWindowTextA, which explicitly use ANSI characters.
Fixed code:
DWORD WINAPI fill_matrix(LPVOID lpParameter)
{
unsigned char a = 'h';
for (int i = 0; i < 8; i++){
for (int j = 0; j <8; j++)
{
char window_text[2] = {a, '\0'};
SetWindowTextA(hWndLabel[i * 8 + j], window_text);
}
}
return 0;
}

Arduino Serial commutation using visual studio c++

I've been working on the school project with Gird-Eye.
I use the Arduino Uno to access the data form Grid-Eye.
And now I want to implement a serial communication test program with c++.
I use the library form here:
http://playground.arduino.cc/Interfacing/CPPWindows
Here is Arduino Code:
int data[64];
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
for (int i = 0; i < 64; ++i) {
data[i] = i;
}
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() > 0) {
char c = Serial.read();
if (c == 'h') { Serial.write("Hello\r\n"); }
else if (c == 'i') {
for (int i = 0; i < 64; ++i)
Serial.println(data[i]);
}
}
}
And Here is main.cpp code:
int main() {
Serial* port = new Serial("COM5");
if (port->IsConnected()) cout << "Connection established!!!" << endl;
char data[256] = "";
int datalength = 256;
int readResult = 0;
for (int i = 0; i < 256; ++i) { data[i] = 0; }
string str;
char command[] = "i";
int msglen = strlen(command);
port->WriteData(command, msglen);
while (1) {
while (port->ReadData(data, 256) != -1) {
printf("%s", data);
}
}
system("pause");
return 0;
}
I can get the value successfully with this interface.
However the window additional shows extra value.
For Example, the program should ends like this.
....
61
62
63
But I get
...
61
62
63
50
51
52
53
I have no idea why there is extra value.
Could anyone tell me why?
Thanks!!!
I believe that you need to terminate the string that you put into the data buffer in each loop iteration:
while ((n = port->ReadData(data, 256)) != -1) {
data[n] = 0;
printf("%s", data);
}

char in string is not in order wanted

I am a beginner and I need some help here. This program prints out the frequency of char in the string, e.g. if user enters zzaaa it prints out a3z2 and what I need to print is z2a3 since z is entered first before a. But I am having a hard time switching the order around. Thanks in advance!
int main
{
int ib, i=0, j=0, k=0;
int count[26] = {0};
char chh[3][10];
for (ib = 0; ib < 3; ib++) // get 3 input
gets(chh[ib]);
for (i = 0; i < 3; i++)
{
for (j = 0; j < 10; j++)
{
if (chh[i][j] >= 'a' && chh[i][j] <= 'z')
{
count[chh[i][j] - 'a']++;
}
}
for (k = 0; k < 26; k++)
{
if (count[k] != 0) // if array location is not equals to 0
printf("%c%d", k + 'a', count[k]);
}
memset(count, 0, sizeof(count)); //reset integer array
printf("\n");
}
It prints a before z because you arranged count from a to z by alphabetic priority not entering priority:
count[chh[i][j] - 'a']
if you want to print them by entering priority you should change it. there are several ways to do this. like this:
#include <stdio.h>
#include <string.h>
int main()
{
int ib, i=0, j=0,k=0, kk=0,c=0,found=0;
int count[26][2];
char chh[3][10];
for (ib = 0; ib < 3; ib++) // get 3 input
gets(chh[ib]);
printf("output is:\n");
for (i=0;i<26;i++)
{
count[i][0]=0;
count[i][1]=0;
}
for (i = 0; i < 3; i++)
{
for (j = 0; j < 10; j++)
{
if (chh[i][j] >= 'a' && chh[i][j] <= 'z')
{
found=0;
for (c=0;c<kk;c++)
if (count[c][0]==chh[i][j])
{
count[c][1]++;
found=1;
break;
}
if (!found)
{
count[c][0]=chh[i][j];
count[c][1]++;
kk++;
}
}
}
for (k = 0; k < 26; k++)
{
if (count[k][1] != 0) // if array location is not equals to 0
printf("%c%d", count[k][0], count[k][1]);
}
memset(count, 0, sizeof(count)); //reset integer array
printf("\n");
}
}

Merge multiple input strings to sort alphabetically

Help! Here I have a program, that sorts input strings alphabetically. The problem is that it sorts the entered strings seperately, but I need them merged and sorted together. What am i doing wrong?
int main (void)
{
char repeat;
do{
char string[128], string1[128], temp;
int n, i, j;
cout<<"\nEnter symbols: "<<endl;
gets(string);
n = strlen(string);
for (i=0; i<n-1; i++)
{
for (j=i+1; j<n; j++)
{
int s = tolower(string[i]) - tolower(string[j]);
if ( s == 0 )
{
s = string[i] - string[j];
}
if (s > 0)
{
temp = string[i];
string[i] = string[j];
string[j] = temp;
}
}
}
cout<<"\nSorted alphabetically: "<<endl;
printf("\n%s", string);
printf("\n");
cout<<"\nEnter more symbols: "<<endl;
gets(string1);
n = strlen(string1);
for (i=0; i<n-1; i++)
{
for (j=i+1; j<n; j++)
{
int s = tolower(string1[i]) - tolower(string1[j]);
if ( s == 0 )
{
s = string1[i] - string1[j];
}
if (s > 0)
{
temp = string1[i];
string1[i] = string1[j];
string1[j] = temp;
}
}
}
cout<<"\nSorted alphabetically: "<<endl;
the function below merges the strings, when they both have been already sorted
strcat(string, string1);
printf(\n%s", string);
printf("\n");
cout << "To repeat press j" << endl;
cin >> repeat;
}
while ( repeat == 'j' );
system("Pause");
return 0;
}
The easiest way is to merge the strings into a new one.
int main (void)
{
char repeat;
do{
char string[128], string1[128],string2[256], temp;
int n, i, j;
cout<<"\nEnter symbols: "<<endl;
gets(string);
cout<<"\nEnter more symbols: "<<endl;
gets(string1);
strcpy (string2,string);
strcat (string2,string1);
// rest of your code here. You only need to sort string2

Resources