C++ Program to Generate Random Hexadecimal Bytes

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.

  1. #include<iostream>
  2. #include<conio.h>
  3. #include<stdlib.h>
  4.  
  5. using namespace std;
  6.  
  7. int main(int argc, char **argv)
  8. {
  9.     int val = rand();
  10.     char Hex[33];
  11.     itoa(val, Hex, 16);
  12.     cout<< "Random Decimal Byte:" << val;
  13.     cout << "\nEquivalent Hex Byte: " << Hex;
  14. }

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.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.