Sar.htm 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <html>
  2. <head>
  3. <title>Blitz3D Docs</title>
  4. <link rel=stylesheet href=../css/commands.css type=text/css>
  5. </head>
  6. <body>
  7. <h1>Sar repetitions</h1>
  8. <h1>Parameters</h1>
  9. <table>
  10. <tr>
  11. <td>
  12. repetitions = number of shifts to make right
  13. </td>
  14. </tr>
  15. </table>
  16. <h1>Description</h1>
  17. <table>
  18. <tr>
  19. <td>
  20. 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 />
  21. <br />
  22. 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 />
  23. The usefulness of this command is basically faster math execution. Also see Shl.
  24. <br>
  25. <br>
  26. See also: <a class=small href=Shl.htm>Shl</a>, <a class=small href=Shr.htm>Shr</a>.
  27. </td>
  28. </tr>
  29. </table>
  30. <h1><a href=../2d_examples/Sar.bb>Example</a></h1>
  31. <table>
  32. <tr>
  33. <td>
  34. ; shl, shr, sar examples <br />
  35. <br />
  36. value = 100 <br />
  37. <br />
  38. ; multiple x 2 <br />
  39. Print "Shift 1 bit left; Value = " + value Shl 1 <br />
  40. ; multiple x 4 <br />
  41. Print "Shift 2 bits left; Value = " + value Shl 2 <br />
  42. ; multiple x 16 <br />
  43. Print "Shift 4 bits left; Value = " + value Shl 4 <br />
  44. ; divide by 2 <br />
  45. Print "Shift 1 bit right; Value = " + value Shr 1 <br />
  46. ; divide by 4 <br />
  47. Print "Shift 2 bits right; Value = " + value Shr 2 <br />
  48. ; divide by 16 <br />
  49. Print "Shift 4 bits right; Value = " + value Shr 4 <br />
  50. <br />
  51. Print "Shift by SAR 4 times = " + value Sar 4 <br />
  52. <br />
  53. WaitKey()
  54. </td>
  55. </tr>
  56. </table>
  57. <br>
  58. <a target=_top href=../index.htm>Index</a><br>
  59. <br>
  60. 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>
  61. </html>