#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <sstream>
usingnamespace std;
char *D[11] = {
"210743AAAEC8E34B",
"7D16AE8F0E67A37E",
"3A3B504AE96F6147",
"A58ADFCA8EB3A217",
"649821C088CD195A",
"DBDBB68209898D44",
"EC1FBB44455CD8D0",
"D2545542803C5F82",
"095720F6301B3065",
"7A4D0B2607D72E55",
"A29B364DF6469A48"
};
int main()
{
// storage for converted values
vector<vector<int>> int_arrays;
bool option1 = false;
if(option1 == true)
{
// iterate through each row
for (auto i : D)
{
// output array
std::cout << i << std::endl;
// temporary storage
vector<int> int_array;
// go through each character
for (int j=0; j < 16; j++)
{
// convert char to int and store in vector
int_array.push_back((int)i[j]);
}
// put converted value in storage
int_arrays.push_back(int_array);
}
}
else
{
// iterate through each row
for (auto i : D)
{
// output array
std::cout << i << std::endl;
std::string string_temp(i);
//temporary storage
vector<int> int_array;
// go through each character
for (int j=0; j < 16; j++)
{
std::stringstream temp;
// convert to hex
temp << std::hex << (int) string_temp[j];
signedint temp_int;
// convert string to int
stringstream(temp.str()) >> temp_int;
int_array.push_back(temp_int);
}
// put converted value in storage
int_arrays.push_back(int_array);
}
}
std::cout << std::endl;
// start of display stored information
// go through each row
for (auto xx : int_arrays)
{
// go through each column
for(int i=0; i < xx.size(); i++)
{
std::cout << xx[i];
}
std::cout << std::endl;
}
int x;
cin >> x;
return 0;
}
Hi, thanks for your replay,
I´´m trying to do this;
literal D[0] = "210743AAAEC8E34B" will be change to long long int F[0] = 0x210743AAAEC8E34B
.
.
.
literal D[10] = "A29B364DF6469A48" will be long long int F[10] = 0xA29B364DF6469A48
Work only when i=0, 1 and 2 F[i], after return wrong numbers.
I appreciate your trying to help me but I´m so beginner to understand your code.
Can you help me with my code? Where is my mistake? Please try to compile my code and see the result.
/*replace
#include <string.h>
#include <iostream>
#include <stdlib.h> */
// with
#include <string>
#include <iostream>
#include <cstdlib>
usingnamespace std;
char *D[11] =
{
"210743AAAEC8E34B",
"7D16AE8F0E67A37E",
"3A3B504AE96F6147",
"A58ADFCA8EB3A217",
"649821C088CD195A",
"DBDBB68209898D44",
"EC1FBB44455CD8D0",
"D2545542803C5F82",
"095720F6301B3065",
"7A4D0B2607D72E55",
"A29B364DF6469A48"
};
longlongint F[11];
char str_1[16];
// use void main or int main
int main( )
{
int i;
for (i = 0; i < 11; ++i)
{
printf("%s\n",D[i]);
}
printf("\n\n");
for (i = 0; i < 11; ++i)
{
strcpy(str_1, D[i]);
// you just need unsigned long long
F[i] = _strtoui64 (str_1, NULL, 16);
printf("%llX \n",F[i]);
}
printf("\n\n");
int x;
cin >> x;
return(0);
}