Note that there are some explanatory texts on larger screens.

plurals
  1. POOctal to binary conversion confusion
    primarykey
    data
    text
    <p>I have a code in C++ which convert 2 digits octal number to binary number. For testing validity of the code I used several online conversion site like </p> <p><a href="http://www.translatorscafe.com/cafe/units-converter/numbers/calculator/octal-to-binary/" rel="nofollow">this</a> and <a href="http://ncalculators.com/digital-computation/binary-octal-converter.htm" rel="nofollow">this</a></p> <p>When I enter 58 or 59 in as an octal value it says invalid octal values but when I enter 58 in my code it gives binary number as - 101000. Again for testing I enter 101000 as binary number in above website's calculator then they gives me result 50 as octal value.</p> <p>I need some explanation why this is so.</p> <p>Here is the C++ code -</p> <pre><code>#include &lt;iostream.h&gt; #include &lt;conio.h&gt; void octobin(int); void main() { clrscr(); int a; cout &lt;&lt; "Enter a 2-digit octal number : "; cin&gt;&gt;a; octobin(a); getch(); } void octobin(int oct) { long bnum=0; int A[6]; //Each octal digit is converted into 3 bits, 2 octal digits = 6 bits. int a1,a2,quo,rem; a2=oct/10; a1=oct-a2*10; for(int x=0;x&lt;6;x++) { A[x]=0; } //Storing the remainders of the one's octal digit in the array. for (x=0;x&lt;3;x++) { quo=a1/2; rem=a1%2; A[x]=rem; a1=quo; } //Storing the remainders of the ten's octal digit in the array. for(x=3;x&lt;6;x++) { quo=a2/2; rem=a2%2; A[x]=rem; a2=quo; } //Obtaining the binary number from the remainders. for(x=x-1;x&gt;=0;x--) { bnum*=10; bnum+=A[x]; } cout &lt;&lt; "The binary number for the octal number " &lt;&lt; oct &lt;&lt; " is " &lt;&lt; bnum &lt;&lt; "." &lt;&lt; endl; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload