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
Here’s the list of Best Books in C++ Programming, Data Structures and Algorithms.
Related Posts:
- Apply for C++ Internship
- Check C++ Books
- Apply for Computer Science Internship
- Check Computer Science Books
- Check Programming Books