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 firstname.lastname@example.org. 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
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- 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
- Difference between Type Casting and Type Conversion
- Type Conversion in C
- Type Conversion in C++
- Catch block and type conversion in C++
- Implicit Type Conversion in C with Examples
- Conversion of whole String to uppercase or lowercase using STL in C++
- Bool data type in C++
- Is there any need of "long" data type in C and C++?
- What is the size_t data type in C?
- What is data type of FILE in C ?
- Data Type Ranges and their macros in C++
- C++ map having key as a user define data type