home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / zkuste / Perl / ActivePerl-5.6.0.613.msi / 䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥 / _c224b8dd8fce29740da1bc8b60a7efaf < prev    next >
Text File  |  2000-03-23  |  10KB  |  302 lines

  1.  
  2. <HTML>
  3. <HEAD>
  4. <TITLE>Bit::ShiftReg - Bit Shift Registers with Rotate / Shift Operations</TITLE>
  5. <LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
  6. <LINK REV="made" HREF="mailto:">
  7. </HEAD>
  8.  
  9. <BODY>
  10. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  11. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  12. <STRONG><P CLASS=block> Bit::ShiftReg - Bit Shift Registers with Rotate / Shift Operations</P></STRONG>
  13. </TD></TR>
  14. </TABLE>
  15.  
  16. <A NAME="__index__"></A>
  17. <!-- INDEX BEGIN -->
  18.  
  19. <UL>
  20.  
  21.     <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
  22.  
  23.     <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
  24.     <LI><A HREF="#description">DESCRIPTION</A></LI>
  25.     <LI><A HREF="#example">EXAMPLE</A></LI>
  26.     <LI><A HREF="#see also">SEE ALSO</A></LI>
  27.     <LI><A HREF="#version">VERSION</A></LI>
  28.     <LI><A HREF="#author">AUTHOR</A></LI>
  29.     <LI><A HREF="#copyright">COPYRIGHT</A></LI>
  30.     <LI><A HREF="#license agreement">LICENSE AGREEMENT</A></LI>
  31. </UL>
  32. <!-- INDEX END -->
  33.  
  34. <HR>
  35. <P>
  36. <H1><A NAME="name">NAME</A></H1>
  37. <P>Bit::ShiftReg - Bit Shift Registers with Rotate / Shift Operations</P>
  38. <P>Implements rotate left, rotate right, shift left and shift right
  39. operations with carry flag for all C integer types</P>
  40. <P>
  41. <HR>
  42. <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
  43. <UL>
  44. <LI>Linux</LI>
  45. <LI>Solaris</LI>
  46. <LI>Windows</LI>
  47. </UL>
  48. <HR>
  49. <H1><A NAME="synopsis">SYNOPSIS</A></H1>
  50. <UL>
  51. <LI>
  52. <A HREF="../../../lib/Pod/perlfunc.html#item_qw"><CODE>use Bit::ShiftReg qw( bits_of_byte bits_of_short bits_of_int bits_of_long</CODE></A>
  53. <CODE>LSB_byte MSB_byte LSB_short MSB_short LSB_int MSB_int LSB_long MSB_long</CODE>
  54. <CODE>ROL_byte ROR_byte SHL_byte SHR_byte ROL_short ROR_short SHL_short SHR_short</CODE>
  55. <CODE>ROL_int ROR_int SHL_int SHR_int ROL_long ROR_long SHL_long SHR_long );</CODE>
  56. <P>imports all (or some, by leaving some out) of the available operations
  57. and functions</P>
  58. <P></P>
  59. <LI>
  60. <A HREF="../../../lib/Pod/perlfunc.html#item_qw"><CODE>use Bit::ShiftReg qw(:all);</CODE></A>
  61. <P>imports all available operations and functions</P>
  62. <P></P>
  63. <LI>
  64. <CODE>$version = Bit::ShiftReg::Version();</CODE>
  65. <P>returns the module's version number</P>
  66. <P></P>
  67. <LI>
  68. <CODE>$bits = bits_of_byte();</CODE>
  69. <P>returns the number of bits in a byte (unsigned char) on your machine</P>
  70. <P></P>
  71. <LI>
  72. <CODE>$bits = bits_of_short();</CODE>
  73. <P>returns the number of bits in an unsigned short on your machine</P>
  74. <P></P>
  75. <LI>
  76. <CODE>$bits = bits_of_int();</CODE>
  77. <P>returns the number of bits in an unsigned int on your machine</P>
  78. <P></P>
  79. <LI>
  80. <CODE>$bits = bits_of_long();</CODE>
  81. <P>returns the number of bits in an unsigned long on your machine</P>
  82. <P></P>
  83. <LI>
  84. <CODE>$lsb = LSB_byte($value);</CODE>
  85. <P>returns the least significant bit (LSB) of a byte (unsigned char)</P>
  86. <P></P>
  87. <LI>
  88. <CODE>$msb = MSB_byte($value);</CODE>
  89. <P>returns the most significant bit (MSB) of a byte (unsigned char)</P>
  90. <P></P>
  91. <LI>
  92. <CODE>$lsb = LSB_short($value);</CODE>
  93. <P>returns the least significant bit (LSB) of an unsigned short</P>
  94. <P></P>
  95. <LI>
  96. <CODE>$msb = MSB_short($value);</CODE>
  97. <P>returns the most significant bit (MSB) of an unsigned short</P>
  98. <P></P>
  99. <LI>
  100. <CODE>$lsb = LSB_int($value);</CODE>
  101. <P>returns the least significant bit (LSB) of an unsigned int</P>
  102. <P></P>
  103. <LI>
  104. <CODE>$msb = MSB_int($value);</CODE>
  105. <P>returns the most significant bit (MSB) of an unsigned int</P>
  106. <P></P>
  107. <LI>
  108. <CODE>$lsb = LSB_long($value);</CODE>
  109. <P>returns the least significant bit (LSB) of an unsigned long</P>
  110. <P></P>
  111. <LI>
  112. <CODE>$msb = MSB_long($value);</CODE>
  113. <P>returns the most significant bit (MSB) of an unsigned long</P>
  114. <P></P>
  115. <LI>
  116. <CODE>$carry = ROL_byte($value);</CODE>
  117. <P></P>
  118. <LI>
  119. <CODE>$carry = ROR_byte($value);</CODE>
  120. <P></P>
  121. <LI>
  122. <CODE>$carry_out = SHL_byte($value,$carry_in);</CODE>
  123. <P></P>
  124. <LI>
  125. <CODE>$carry_out = SHR_byte($value,$carry_in);</CODE>
  126. <P></P>
  127. <LI>
  128. <CODE>$carry = ROL_short($value);</CODE>
  129. <P></P>
  130. <LI>
  131. <CODE>$carry = ROR_short($value);</CODE>
  132. <P></P>
  133. <LI>
  134. <CODE>$carry_out = SHL_short($value,$carry_in);</CODE>
  135. <P></P>
  136. <LI>
  137. <CODE>$carry_out = SHR_short($value,$carry_in);</CODE>
  138. <P></P>
  139. <LI>
  140. <CODE>$carry = ROL_int($value);</CODE>
  141. <P></P>
  142. <LI>
  143. <CODE>$carry = ROR_int($value);</CODE>
  144. <P></P>
  145. <LI>
  146. <CODE>$carry_out = SHL_int($value,$carry_in);</CODE>
  147. <P></P>
  148. <LI>
  149. <CODE>$carry_out = SHR_int($value,$carry_in);</CODE>
  150. <P></P>
  151. <LI>
  152. <CODE>$carry = ROL_long($value);</CODE>
  153. <P></P>
  154. <LI>
  155. <CODE>$carry = ROR_long($value);</CODE>
  156. <P></P>
  157. <LI>
  158. <CODE>$carry_out = SHL_long($value,$carry_in);</CODE>
  159. <P></P>
  160. <LI>
  161. <CODE>$carry_out = SHR_long($value,$carry_in);</CODE>
  162. <P></P></UL>
  163. <P><STRONG>Note that ``$value'' must be a variable in the calls of the functions</STRONG>
  164. <STRONG>ROL, ROR, SHL and SHR, and that the contents of this variable are</STRONG>
  165. <STRONG>altered IMPLICITLY by these functions!</STRONG></P>
  166. <P><STRONG>Note also that the ``carry'' input value is always truncated to the least</STRONG>
  167. <STRONG>significant bit, i.e., input values for ``carry'' must be either 0 or 1!</STRONG></P>
  168. <P><STRONG>Finally, note that the return values of the functions LSB, MSB, ROL, ROR,</STRONG>
  169. <STRONG>SHL and SHR are always either 0 or 1!</STRONG></P>
  170. <P>
  171. <HR>
  172. <H1><A NAME="description">DESCRIPTION</A></H1>
  173. <P>This module implements rotate left, rotate right, shift left and shift
  174. right operations with carry flag for all C integer types.</P>
  175. <P>The results depend on the number of bits that the integer types unsigned
  176. char, unsigned short, unsigned int and unsigned long have on your machine.</P>
  177. <P>The module automatically determines the number of bits of each integer type
  178. and adjusts its internal constants accordingly.</P>
  179. <P>How the operations work:</P>
  180. <DL>
  181. <DT><STRONG><A NAME="item_ROL">ROL</A></STRONG><BR>
  182. <DD>
  183. Rotate Left:
  184. <PRE>
  185.  carry:                           value:</PRE>
  186. <PRE>
  187.  +---+            +---+---+---+---     ---+---+---+---+
  188.  | 1 |  <---+---  | 1 | 0 | 0 | 1  ...  1 | 0 | 1 | 1 |  <---+
  189.  +---+      |     +---+---+---+---     ---+---+---+---+      |
  190.             |                                                |
  191.             +------------------------------------------------+</PRE>
  192. <P></P>
  193. <DT><STRONG><A NAME="item_ROR">ROR</A></STRONG><BR>
  194. <DD>
  195. Rotate Right:
  196. <PRE>
  197.                         value:                          carry:</PRE>
  198. <PRE>
  199.         +---+---+---+---     ---+---+---+---+           +---+
  200.  +--->  | 1 | 0 | 0 | 1  ...  1 | 0 | 1 | 1 |  ---+---> | 1 |
  201.  |      +---+---+---+---     ---+---+---+---+     |     +---+
  202.  |                                                |
  203.  +------------------------------------------------+</PRE>
  204. <P></P>
  205. <DT><STRONG><A NAME="item_SHL">SHL</A></STRONG><BR>
  206. <DD>
  207. Shift Left:
  208. <PRE>
  209.  carry                        value:                       carry
  210.   out:                                                      in:
  211.  +---+        +---+---+---+---     ---+---+---+---+        +---+
  212.  | 1 |  <---  | 1 | 0 | 0 | 1  ...  1 | 0 | 1 | 1 |  <---  | 1 |
  213.  +---+        +---+---+---+---     ---+---+---+---+        +---+</PRE>
  214. <P></P>
  215. <DT><STRONG><A NAME="item_SHR">SHR</A></STRONG><BR>
  216. <DD>
  217. Shift Right:
  218. <PRE>
  219.  carry                        value:                       carry
  220.   in:                                                       out:
  221.  +---+        +---+---+---+---     ---+---+---+---+        +---+
  222.  | 1 |  --->  | 1 | 0 | 0 | 1  ...  1 | 0 | 1 | 1 |  --->  | 1 |
  223.  +---+        +---+---+---+---     ---+---+---+---+        +---+</PRE>
  224. <P></P></DL>
  225. <P>
  226. <HR>
  227. <H1><A NAME="example">EXAMPLE</A></H1>
  228. <P>Suppose you want to implement shift registers in a machine-independent
  229. way.</P>
  230. <P>The only C integer type whose length in bits you can be pretty sure about
  231. is probably a byte, since the C standard only prescribes minimum lengths
  232. for char, short, int and long and that <CODE>sizeof(char)</CODE> <CODE><=</CODE>
  233. <CODE>sizeof(short)</CODE> <CODE><=</CODE> <CODE>sizeof(int)</CODE> <CODE><=</CODE> <CODE>sizeof(long)</CODE>.</P>
  234. <P>How to implement a 4-byte shift register and the 4 operations ROL, ROR,
  235. SHL and SHR on it:</P>
  236. <P>First, you need to define 4 byte registers:</P>
  237. <PRE>
  238.   $byte0 = 0;
  239.   $byte1 = 0;
  240.   $byte2 = 0;
  241.   $byte3 = 0;</PRE>
  242. <P>Then proceed as follows:</P>
  243. <DL>
  244. <DT><STRONG>ROL</STRONG><BR>
  245. <DD>
  246. Rotate left:
  247. <PRE>
  248.   $carry = SHL_byte($byte3, SHL_byte($byte2, SHL_byte($byte1,
  249.            SHL_byte($byte0, MSB_byte($byte3)))));</PRE>
  250. <P></P>
  251. <DT><STRONG>ROR</STRONG><BR>
  252. <DD>
  253. Rotate right:
  254. <PRE>
  255.   $carry = SHR_byte($byte0, SHR_byte($byte1, SHR_byte($byte2,
  256.            SHR_byte($byte3, LSB_byte($byte0)))));</PRE>
  257. <P></P>
  258. <DT><STRONG>SHL</STRONG><BR>
  259. <DD>
  260. Shift left:
  261. <PRE>
  262.   $carry_out = SHL_byte($byte3, SHL_byte($byte2, SHL_byte($byte1,
  263.                SHL_byte($byte0, $carry_in))));</PRE>
  264. <P></P>
  265. <DT><STRONG>SHR</STRONG><BR>
  266. <DD>
  267. Shift right:
  268. <PRE>
  269.   $carry_out = SHR_byte($byte0, SHR_byte($byte1, SHR_byte($byte2,
  270.                SHR_byte($byte3, $carry_in))));</PRE>
  271. <P></P></DL>
  272. <P>
  273. <HR>
  274. <H1><A NAME="see also">SEE ALSO</A></H1>
  275. <P>perl(1), perlsub(1), perlmod(1), perlxs(1), perlxstut(1), perlguts(1).</P>
  276. <P>
  277. <HR>
  278. <H1><A NAME="version">VERSION</A></H1>
  279. <P>This man page documents Bit::ShiftReg version 2.0.</P>
  280. <P>
  281. <HR>
  282. <H1><A NAME="author">AUTHOR</A></H1>
  283. <P>Steffen Beyer <<A HREF="mailto:sb@sdm.de">sb@sdm.de</A>>.</P>
  284. <P>
  285. <HR>
  286. <H1><A NAME="copyright">COPYRIGHT</A></H1>
  287. <P>Copyright (c) 1997 by Steffen Beyer. All rights reserved.</P>
  288. <P>
  289. <HR>
  290. <H1><A NAME="license agreement">LICENSE AGREEMENT</A></H1>
  291. <P>This package is free software; you can redistribute it
  292. and/or modify it under the same terms as Perl itself.</P>
  293. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  294. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  295. <STRONG><P CLASS=block> Bit::ShiftReg - Bit Shift Registers with Rotate / Shift Operations</P></STRONG>
  296. </TD></TR>
  297. </TABLE>
  298.  
  299. </BODY>
  300.  
  301. </HTML>
  302.