Category: base-conversion

Modify an array by sorting after reversal of bits of each array element

  #include using namespace std;  int binaryToDecimal(string n){    string num = n;    int dec_value = 0;          int base = 1;      int len = num.length();    for (int i = len – 1; i >= 0; i–) {        if (num[i] == ‘1’)            dec_value += base;        base = base * 2;    }      return dec_value;}  string decimalToBinary(int n){        string binstr = “”;      while (n > 0) {                          binstr += (n % 2 + 48);        n = […]

Continue Reading