Skip to content

Commit

Permalink
improved code
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Bender committed Mar 28, 2018
1 parent 18d86c9 commit 6c5128e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions conversions/binary2octal.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ int three_digits(int n)
for(int i=0; i<3; i++)
{
r = n%10;
d = d + r * p;
p = p * 10;
n = n / 10;
d += r * p;
p *= 10;
n /= 10;
}
return d;
}
Expand All @@ -30,21 +30,21 @@ int main(void)

else td = binary_num;

binary_num = binary_num / 1000;
binary_num /= 1000;

d = 0, base =1;

// Converting the last three digits to decimal
while(td > 0)
{
remainder = td % 10;
td = td / 10;
d = d + (base * remainder);
base = base * 2;
td /= 10;
d += (base * remainder);
base *= 2;
}

res = res + d * ord; // Calculating the octal value
ord = ord * 10;
res += d * ord; // Calculating the octal value
ord *= 10;
}

printf("\nOctal equivalent is: %d", res);
Expand Down

0 comments on commit 6c5128e

Please sign in to comment.