42 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
#include <string>
 | 
						|
#include <iomanip>
 | 
						|
using std::string;
 | 
						|
 | 
						|
template<typename T>
 | 
						|
void PrintHex(T& obj) {
 | 
						|
	auto size = sizeof(T);
 | 
						|
	std::cout << std::hex << type_name<T>().View() << "<" << size <<"> " << " = 0x";
 | 
						|
	char* ptr = (char*)&obj;
 | 
						|
	for (int i = 0; i < size; i++) {
 | 
						|
		std::cout << std::hex << std::setw(2) << std::setfill('0') <<(int)(uint8_t)*(ptr + i);
 | 
						|
	}
 | 
						|
	std::cout << "FF" << std::endl;
 | 
						|
}
 | 
						|
template<typename T>
 | 
						|
void PrintHex8(T& obj) {
 | 
						|
	auto size = sizeof(T);
 | 
						|
	std::cout << std::hex << type_name<T>().View() << "<" << size << "> " << "\n\t";
 | 
						|
	{
 | 
						|
		int* ptr = (int*)&obj;
 | 
						|
		for (int i = 0; i < size / 4; i += 1) {
 | 
						|
			std::cout << std::dec << std::setw(8) << std::setfill('0') << *(ptr + i) << "-";
 | 
						|
		}
 | 
						|
		std::cout << "=-0x";
 | 
						|
	}
 | 
						|
	{
 | 
						|
		uintptr_t* ptr = (uintptr_t*)&obj;
 | 
						|
		for (int i = 0; i < size / 8; i += 1) {
 | 
						|
			std::cout << std::hex << std::setw(16) << std::setfill('0') << *(ptr + i) << "-";
 | 
						|
		}
 | 
						|
		std::cout << ";-" << std::endl;
 | 
						|
	}
 | 
						|
}
 | 
						|
void TestString1() {
 | 
						|
	string hello = "abcdef";
 | 
						|
	int size = sizeof(string);
 | 
						|
	PrintHex(hello);
 | 
						|
	hello = "abcdefabcdefabcdefabcdef";
 | 
						|
	PrintHex(hello);
 | 
						|
	//hello.~basic_string();
 | 
						|
	PrintHex(size);
 | 
						|
} |