| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <html>
- <head>
- <title>Blitz3D Docs</title>
- <link rel=stylesheet href=../css/commands.css type=text/css>
- </head>
- <body>
- <h1>Sar repetitions</h1>
- <h1>Parameters</h1>
- <table>
- <tr>
- <td>
- repetitions = number of shifts to make right
- </td>
- </tr>
- </table>
- <h1>Description</h1>
- <table>
- <tr>
- <td>
- This performs a right binary shift on the value the specified number of times. This basically is a faster method of dividing the value exponentially. By shifting right once, you are dividing the value by 2. By shifting right twice, you divide by 4, etc.
<br />
-
<br />
- Sar command varies from Shr whereas it fills blank bits shifted with copies of the sign bit, 0 for positive numbers and 1 for negative.
<br />
- The usefulness of this command is basically faster math execution. Also see Shl.
- <br>
- <br>
- See also: <a class=small href=Shl.htm>Shl</a>, <a class=small href=Shr.htm>Shr</a>.
- </td>
- </tr>
- </table>
- <h1><a href=../2d_examples/Sar.bb>Example</a></h1>
- <table>
- <tr>
- <td>
- ; shl, shr, sar examples
<br />
-
<br />
- value = 100
<br />
-
<br />
- ; multiple x 2
<br />
- Print "Shift 1 bit left; Value = " + value Shl 1
<br />
- ; multiple x 4
<br />
- Print "Shift 2 bits left; Value = " + value Shl 2
<br />
- ; multiple x 16
<br />
- Print "Shift 4 bits left; Value = " + value Shl 4
<br />
- ; divide by 2
<br />
- Print "Shift 1 bit right; Value = " + value Shr 1
<br />
- ; divide by 4
<br />
- Print "Shift 2 bits right; Value = " + value Shr 2
<br />
- ; divide by 16
<br />
- Print "Shift 4 bits right; Value = " + value Shr 4
<br />
-
<br />
- Print "Shift by SAR 4 times = " + value Sar 4
<br />
-
<br />
- WaitKey()
- </td>
- </tr>
- </table>
- <br>
- <a target=_top href=../index.htm>Index</a><br>
- <br>
- Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=Sar&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
- </html>
|