This code gives result as binary of the array values written eg: {15,127,7} the output was 11111111111111, can anyone help to modify this to get an output with fixed binary number irrespective of the number given. that means whatever value smaller value i am typing for 127 i should get output with 7 bit .
#include <iostream>
#include<vector>
using namespace std;
int main()
{
long binary_number ;
vector <int> binary;
int decimals[3]={15,127,7};
You could use LB's method with std::setfill1 and std::setw2 from the iomanip3 library
Or even use a std::bitset4 with the number of bits you want it to be. Then when you output use tostring5 method if you want it in binary otherwise use the toulong6 or toullong7 (long long) methods for decimal.