Here is a little hacky way of doing it for byte I found some time ago. I think it's worth linking here despite it not being the best solution.
http://gynvael.coldwind.pl/n/c_cpp_number_to_binary_string_01011010
void to_bin(unsigned char c, char *out) {
*(unsigned long long*)out = 0x3030303030303030ULL // ASCII '0'*8
+ (((c * 0x8040201008040201ULL) // spread out eight copies of c
>>7) & 0x101010101010101ULL); // shift to LSB & mask
}
Method provided by @cmaster is optimal and clean. Doing it in parts of 8 bits could be better though. You would construct the table in a loop using your method to avoid writing 256 strings manually. I don't think memory would be an issue too (it would take about 2kB).
Although I don't think there is a way to do it for variable of any size without loop.