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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- 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
- Catch block and type conversion in C++
- std::oct , std::dec and std::hex in C++
- Type Conversion in C
- Type Conversion in C++
- Implicit Type Conversion in C with Examples
- ios manipulators hex() function in C++
- Operations on struct variables in C
- Struct Hack
- Is sizeof for a struct equal to the sum of sizeof of each member?
- How to create an unordered_set of user defined class or struct in C++?
- Data Conversion in C++
- Conversion of whole String to uppercase or lowercase using STL in C++
- Data type of character constants in C and C++
- Data Type Ranges and their macros in C++
- Comparison of boolean data type in C++ and Java
- Is there any need of "long" data type in C and C++?