converting from decimal to binary with arduino

I have an arduino board, which has a language very very similar to c++ and I'd like to know how to write a program that converts decimal to binary, I've looked around he archives and i can find plenty of threads about issues people are having with such a program but none on how to go about making such a program. I know the process of creating 8 bit binary, just not how to code it.
What do you want to do exactly? All numbers are stored in binary form on a computer. There is no need to convert anything.
I want it to print the number in an array, its, one step of a much bigger program, which before you ask I'm not sure about, I'm doing it one tiny bit at a time.
Will something like this work for you?

1
2
3
4
5
6
7
#include <bitset>

std::string binary(unsigned long val)
{
    std::bitset<sizeof(unsigned long)> x(val);
    return x.to_string();
}
Topic archived. No new replies allowed.