This is a portable implementation for converting a character or an integer to its binary text equivalent.
It makes use of the CHAR_BIT constant (which is defined in the header file climits) to get the number of bits a byte consists of on the implementation where you compile this code on.
Further for simplicity, it makes use of STL: bitset :)
To understand how the program works, I advise you to just compile and run it.
When you run the program, it will ask you to enter a character
(or an integer, in case you're running the integer converter).
After you've pressed the ENTER key, the program will display the corresponding binary value.
I've also supplied some sample output, in case you're not be able to compile the code directly, you could take a look at that first.

/* Character to binary */
#include <iostream>
#include <bitset>
#include <climits>

int main()
{
    std::bitset<CHAR_BIT> byte;
    char ch;
    
    std::cout << "Enter a character: ";
    std::cin >> ch;
    byte |= ch;
    std::cout << "Binary representation: " << byte << std::endl;
}

/*
 My output
 
 Enter a character: a
 Binary representation: 01100001
*/

/* Integer to binary */
#include <iostream>
#include <bitset>
#include <climits>

int main()
{
    std::bitset<CHAR_BIT * sizeof(int)> binary;
    int i;
    
    std::cout << "Enter an integer: ";
    std::cin >> i;
    binary |= i;
    std::cout << "Binary representation: " << binary << std::endl;
}

/*
 My output:
 
 Enter an integer: 59
 Binary representation: 00000000000000000000000000111011
*/

Interesting. The only way I remember using bitset is in a template function, with bitset passed the value in its initializer.

By the way, you can use numeric_limits<T>::digits instead of sizeof()

The article starter has earned a lot of community kudos, and such articles offer a bounty for quality replies.