This is a C++ Program to generate random hex bytes. The idea is to genrate decimal number first and convert it to hexadecimal.
Here is source code of the C++ Program to Generate Random Hexadecimal Bytes. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
#include<iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;
int main(int argc, char **argv)
{
int val = rand();
char Hex[33];
itoa(val, Hex, 16);
cout<< "Random Decimal Byte:" << val;
cout << "\nEquivalent Hex Byte: " << Hex;
}
Output:
$ g++ GenerateHexByte.cpp $ a.out Random Decimal Byte:41 Equivalent Hex Byte: 29
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
advertisement
advertisement
Here’s the list of Best Books in C++ Programming, Data Structures and Algorithms.
Next Steps:
- Get Free Certificate of Merit in C++ Programming
- Participate in C++ Programming Certification Contest
- Become a Top Ranker in C++ Programming
- Take C++ Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Practice Programming MCQs
- Buy C++ Books
- Buy Computer Science Books
- Apply for Computer Science Internship
- Apply for Information Technology Internship