vector<int> bin(int num) { vector<int> binaryNum; if (num == 0) { binaryNum.push_back(0); return binaryNum; } while (num > 0) { binaryNum.push_back(num % 2); num = num / 2; } reverse(binaryNum.begin(), binaryNum.end()); return binaryNum; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter