int *dec_binary(int i)
{
int n = 0;
int k = 1;
int *p = NULL;
while (i / 2) {
k++;
p = (int *)realloc(p, sizeof(int) * k);
p[n++] = i % 2;
i /= 2;
}
p[n++] = i;
p[n] = 9;
for (int k = 0; k < n / 2; k++) {
int temp = p[k];
p[k] = p[n - k -1];
p[n -k -1] = temp;
}
return p;
}
int dec_to_oct(int i)
{
int result = 0;
int n = 0;
int first_number = 0;
if (i < 8)
return i;
while (i / 8){
first_number = i % 8;
i /= 8;
n++;
if (n > 1){
int temp = 0;
temp = n - 1;
while (temp--)
first_number *= 10;
first_number += result;
}
else
result = first_number;
result = first_number;
}
while (n--)
i *= 10;
i += first_number;
return i;
}
int oct_dec(int i)
{
int result = 0;
int n = 0;
int number = 0;
if (i < 10)
return i;
while (i / 10) {
number = i % 10;
result += (number * powl(8, n));
n++;
i /= 10;
}
result += (i * powl(8, n));
return result;
}
int bin_dec(int number)
{
int result = 0;
int n = 0;
int p[10];
int k = 0;
while(number / 10) {
p[k++] = number % 10;
number /= 10;
}
p[k++] = number;
p[k] = '\n';
int j = 0;
for (int i = 0; i < k / 2; i++) {
int temp = p[i];
p[i] = p[k - i -1];
p[k -i -1] = temp;
}
int l = 0;
while(p[l] != '\n')
cout << p[l++];
cout << endl;
k--;
while (p[n] != '\n') {
result += (p[n] * powl(2, k));
n++;
k--;
}
return result;
}