int a = 5;
int* b = &a;
std::vector<char> arr;
arr.reserve(sizeof(int*));
char* val = reinterpret_cast<char*>(b);
for(size_t i = 0; i < sizeof(int*); ++i)
{
arr.push_back(val[i]);
}
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdint>
int main()
{
int a = 5;
std::uintptr_t b = reinterpret_cast<std::uintptr_t>(&a);
std::cout << "0x" << std::hex << b << " " << sizeof(b) << std::endl;
std::vector<unsigned char> data(sizeof(b));
for (int i = 0; i < data.size(); i++)
{
data[data.size() - 1 - i] = (b >> (i * 8));
}
for (int i = 0; i < data.size(); i++)
{
std::cout << std::setw(2) << std::setfill('0') << std::hex << (unsigned)data[i] << " ";
}
return 0;
}