Most of the log files produced in system are either in binary(0,1) or hex(0x) formats. Sometimes you might need to map this data into readable format.
Conversion of this hex information into system defined data types such as ‘int/string/float’ is comparatively easy. On the other hand when you have some user defined data types such as ‘struct’ the process can be complicated.
Following basic program will help you with above mentioned operation. While implementing in real world you need more error handling.
After conversion from struct to hex string: 0x01 0x00 0x00 0x00 0x52 0x6f 0x68 0x69 0x74 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 After Conversion form hex to struct: Id : 1 Name : Rohit
This article is contributed by Rohit Kasle. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Converting string to number and vice-versa in C++
- How to convert C style strings to std::string and vice versa?
- C Program for Lower Case to Uppercase and vice-versa in a file
- Type Conversion in C++
- Type Conversion in C
- Catch block and type conversion in C++
- What is the size_t data type in C?
- Bool data type in C++
- What is data type of FILE in C ?
- Is there any need of "long" data type in C and C++?
- Conversion of whole String to uppercase or lowercase using STL in C++
- C++ map having key as a user define data type
- C++ set for user define data type
- Data Type Ranges and their macros in C++
- Data type of character constants in C and C++