Home Forums C Programming function Reply To: function

#3431
Humayan
Participant

binary conversion:
 

#include 
void main()
{
 int i;
 cout << "Enter a number to convert ";
 cin >> i;
 int binaryArray [ 20 ] ; //whatever
 int j = 0;
 while ( i )
 {
  binaryArray [ j ++ ] = i % 2 ;
  i /= 2;
 }
 
 cout << endl << "Binary Version: " ;
 while ( j -- > 0 )
  cout << binaryArray [ j  ];
 cout << endl;
}

 
 
hex conversion:

#include 
void printHex ( int i );
void main()
{
 cout << "Enter a character: " ;
 char ch;
 cin >> ch;
 cout << endl << "Here is hex form of ASCII: " << endl;
 printHex ( ( int ) ch );
 cout << endl;
 
 
 
}
void printHex ( int i )
{
 char base16 [ 17 ] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' };
 
 if ( i == 0 )
  return;
 else
 {
  printHex ( i / 16 );
  cout << base16 [ i % 16 ];
 }
}

 
Is the merge sort on an array??