http://beebwiki.mdfs.net/index.php?title=Left_shift&feed=atom&action=history
Left shift - Revision history
2024-03-29T11:55:19Z
Revision history for this page on the wiki
MediaWiki 1.30.0-rc.0
http://beebwiki.mdfs.net/index.php?title=Left_shift&diff=4612&oldid=prev
Jgharston: Added universal routines.
2024-01-15T15:18:44Z
<p>Added universal routines.</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr style="vertical-align: top;" lang="en">
<td colspan="2" style="background-color: white; color:black; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: white; color:black; text-align: center;">Revision as of 15:18, 15 January 2024</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l54" >Line 54:</td>
<td colspan="2" class="diff-lineno">Line 54:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>== Notes ==</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>== Notes ==</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"></del></div></td><td colspan="2"> </td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>The operation is mathematically equivalent to unsigned integer</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>The operation is mathematically equivalent to unsigned integer</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>multiplication by the respective power of two.  By contrast the expression</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>multiplication by the respective power of two.  By contrast the expression</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l72" >Line 72:</td>
<td colspan="2" class="diff-lineno">Line 71:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>on either side.  For example:</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>on either side.  For example:</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline"> </del>IF (dword% << 24) = &1000000 THEN ...</div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">    </ins>IF (dword% << 24) = &1000000 THEN ...</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>See <code>[[=]]</code> for more details.</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>See <code>[[=]]</code> for more details.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline"><code>((num%AND&3FFFFFFF)*2)OR(((num%AND&40000000)<>)AND&80000000)</code></del></div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">==Compatibility==</ins></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline">has </del>the <del class="diffchange diffchange-inline">same effect as </del><code><del class="diffchange diffchange-inline">(num% </del><< 1<del class="diffchange diffchange-inline">)</del></code> and <del class="diffchange diffchange-inline">is usable </del>on <del class="diffchange diffchange-inline">all </del>BBC</div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">The following routines will do a binary left shift, </ins>the <ins class="diffchange diffchange-inline">equivalent of </ins><code><< 1</code><ins class="diffchange diffchange-inline">,</ins></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline">BASICs.</del></div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>and <ins class="diffchange diffchange-inline">a binary left rotate </ins>on <ins class="diffchange diffchange-inline">any </ins>BBC <ins class="diffchange diffchange-inline">BASIC:</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline">– </del>[[User:Beardo|beardo]] 02:54, 3 September 2011 (UTC)</div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">    REM Shift Left:  abcdefgh -> bcdefgh0</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">    DEFFNshl(A%)=((A%AND&3FFFFFFF)*2)OR(((A%AND&40000000)>0)AND&80000000)</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">    :</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">    REM Rotate Left:  abcdefgh -> bcdefgha</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">    DEFFNrol(A%)=((A%AND&3FFFFFFF)*2)OR(((A%AND&40000000)<>0)AND&80000000)OR-(A%<0)</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">    :</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>[[User:Beardo|beardo]] 02:54, 3 September 2011 (UTC<ins class="diffchange diffchange-inline">)</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">[[User:Jgharston|Jgharston]] ([[User talk:Jgharston|talk]]) 16:18, 15 January 2024 (CET</ins>)</div></td></tr>
</table>
Jgharston
http://beebwiki.mdfs.net/index.php?title=Left_shift&diff=1558&oldid=prev
WikiSysop: 1 revision
2015-03-08T18:12:43Z
<p>1 revision</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<tr style="vertical-align: top;" lang="en">
<td colspan="1" style="background-color: white; color:black; text-align: center;">← Older revision</td>
<td colspan="1" style="background-color: white; color:black; text-align: center;">Revision as of 18:12, 8 March 2015</td>
</tr><tr><td colspan="2" style="text-align: center;" lang="en"><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>
WikiSysop
http://beebwiki.mdfs.net/index.php?title=Left_shift&diff=326&oldid=prev
WikiSysop: 1 revision
2015-03-08T00:13:07Z
<p>1 revision</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<tr style="vertical-align: top;" lang="en">
<td colspan="1" style="background-color: white; color:black; text-align: center;">← Older revision</td>
<td colspan="1" style="background-color: white; color:black; text-align: center;">Revision as of 00:13, 8 March 2015</td>
</tr><tr><td colspan="2" style="text-align: center;" lang="en"><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>
WikiSysop
http://beebwiki.mdfs.net/index.php?title=Left_shift&diff=1557&oldid=prev
WikiSysop: 1 revision
2013-08-28T22:58:16Z
<p>1 revision</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<tr style="vertical-align: top;" lang="en">
<td colspan="1" style="background-color: white; color:black; text-align: center;">← Older revision</td>
<td colspan="1" style="background-color: white; color:black; text-align: center;">Revision as of 22:58, 28 August 2013</td>
</tr><tr><td colspan="2" style="text-align: center;" lang="en"><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>
WikiSysop
http://beebwiki.mdfs.net/index.php?title=Left_shift&diff=325&oldid=prev
Jgharston: Minor formatting tweeks
2011-12-25T22:18:22Z
<p>Minor formatting tweeks</p>
<p><b>New page</b></p><div>[[Category:BASIC keywords]]<br />
Left shift, '''<<''', is a ''bitwise operator'' to shift a binary value to the left.<br />
<br />
{| class="wikitable"<br />
|+ <<<br />
| Availability<br />
| colspan="2" | BASIC V<br />
|- style="vertical-align:top"<br />
| [[BASIC metasyntax|Syntax]]<br />
| BASIC V<br />
| <num-var> = <numeric> <code><<</code> <numeric><br />
|- style="vertical-align:top"<br />
| Token (hex)<br />
| BASIC V<br />
| <code>3C 3C</code> (operator)<br />
|- style="vertical-align:top"<br />
| Description<br />
| BASIC V<br />
| Returns the first operand, with the bits of its binary representation shifted toward the most significant end by the number of places specified in the second operand, and zeroes shifted in at the least significant end.<br />
|- style="vertical-align:top"<br />
| Associated keywords<br />
| colspan="2" | <code>[[Arithmetic right shift|>>]]</code>, <code>[[Logical right shift|>>>]]</code>, <code>[[AND]]</code>, <code>[[DIV]]</code>, <code>[[EOR]]</code>, <code>[[NOT]]</code>, <code>[[OR]]</code><br />
|}<br />
<br />
== Description ==<br />
<br />
<code><<</code> accepts two integer values, and returns the first value<br />
''left-shifted'' by the number of binary places given in the second operand. <br />
For instance, in the statement<br />
<br />
PRINT ~&87654321 << 4<br />
<br />
the binary digits of &87654321, 10000111011001010100001100100001, are moved<br />
four places to the left in the register. In this case, the four most<br />
significant bits (1000) are discarded, and the units' place (bit 0) becomes<br />
the sixteens' place (bit 4) of the returned value. As it is a ''logical<br />
shift'', zeroes are shifted in at the bottom, so that bits 0 to 3 of the<br />
result are all 0s. BASIC performs the shift in a single instruction, but if<br />
we consider the shift as a step-by-step calculation, it may be represented<br />
as:<br />
<br />
Operand 10000111011001010100001100100001<br />
/<br />
1st shift 00001110110010101000011001000010 â†<br />
/<br />
2nd shift 00011101100101010000110010000100 â†<br />
/<br />
3rd shift 00111011001010100001100100001000 â†<br />
/<br />
4th shift 01110110010101000011001000010000 â†<br />
The output from the statement is:<br />
>PRINT ~&87654321 << 4<br />
76543210<br />
<br />
== Notes ==<br />
<br />
The operation is mathematically equivalent to unsigned integer<br />
multiplication by the respective power of two. By contrast the expression<br />
<code>A% = Q% * 2^N%</code> causes an error if the signed integer<br />
<code>A%</code> would overflow and although <code>A% = A%+A%</code> is an<br />
unsigned left shift on Acorn/Wilson BASICs, it causes an overflow error on<br />
Russell BASICs. <code><<</code> also takes the two's complement of a<br />
negative shift distance.<br />
<br />
On ARM processors, a shift distance between 32 and 255 inclusive returns<br />
zero; any larger, or negative, distance <code>N%</code> has the same effect<br />
as <code>N% AND 255</CODE>. BASIC on other architectures may give different<br />
results when the second operand is more than 31 or less than 0.<br />
<br />
As a Group 5 operator <code><<</code> does not associate with other Group 5<br />
operators, so parentheses must be used when an operand has such an operator<br />
on either side. For example:<br />
<br />
IF (dword% << 24) = &1000000 THEN ...<br />
<br />
See <code>[[=]]</code> for more details.<br />
<br />
<code>((num%AND&3FFFFFFF)*2)OR(((num%AND&40000000)<>)AND&80000000)</code><br />
has the same effect as <code>(num% << 1)</code> and is usable on all BBC<br />
BASICs.<br />
<br />
– [[User:Beardo|beardo]] 02:54, 3 September 2011 (UTC)</div>
Jgharston