Note that there are some explanatory texts on larger screens.

plurals
  1. POIs this a correct implementation of operator<< / >>?
    text
    copied!<p>are these correct implementations of the operator&lt;&lt; and >> for bitshifting? for some reason, in my operator/, where it only involves these 2 operators, something is allowing for a silly jump that is causing division to be done incorrectly.</p> <pre><code> // the value is stored msb in a list of uint8_t // so 0x123456 will be stored in the list as {0x12, 0x34, 0x56} integer operator&lt;&lt;(size_t shift){ std::list &lt;uint8_t&gt; out = value; for(unsigned int i = 0; i &lt; (shift &gt;&gt; 3); i++) out.push_back(0); shift &amp;= 7; if (shift){ out.push_front(0); std::list &lt;uint8_t&gt;::iterator i = out.begin(), j = out.end(); i++; j--; for(; i != j; i++){ uint8_t temp = *i &gt;&gt; (8 - shift); --i; *i += temp; i++; *i = (uint8_t) (*i &lt;&lt; shift); } uint8_t temp = *i &gt;&gt; (8 - shift); i--; *i += temp; i++; *i &lt;&lt;= shift; } return integer(out); } integer operator&gt;&gt;(size_t shift){ std::list &lt;uint8_t&gt; out = value; for(unsigned int i = 0; i &lt; (shift &gt;&gt; 3); i++) out.pop_back(); shift &amp;= 7; if (shift){ std::list &lt;uint8_t&gt;::reverse_iterator i = out.rbegin(), j = out.rend(); j--; for(; i != j; i++){ *i &gt;&gt;= shift; i++; uint8_t temp = *i &lt;&lt; (8 - shift); i--; *i += temp; } *j &gt;&gt;= shift; } return integer(out); } </code></pre> <p>heres what im doing:</p> <pre><code>integer(1234567) / integer(6) inside division algorithm (long division): numerator largest multiple of denomiator &lt; numeator 12d687 0c0000 06d687 060000 d687 c000 1687 0c00 0a87 0600 0487 0300 0187 0c &lt;-- where did this come from?? 017b 0180 </code></pre> <p>is the error in one of the operators shown or in some other operator?</p> <p>heres my entire code: <a href="http://ideone.com/ncq9S" rel="nofollow">http://ideone.com/ncq9S</a></p>
 

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