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 >
Wrap
Text File
|
2000-03-23
|
10KB
|
302 lines
<HTML>
<HEAD>
<TITLE>Bit::ShiftReg - Bit Shift Registers with Rotate / Shift Operations</TITLE>
<LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
<LINK REV="made" HREF="mailto:">
</HEAD>
<BODY>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> Bit::ShiftReg - Bit Shift Registers with Rotate / Shift Operations</P></STRONG>
</TD></TR>
</TABLE>
<A NAME="__index__"></A>
<!-- INDEX BEGIN -->
<UL>
<LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
<LI><A HREF="#synopsis">SYNOPSIS</A></LI>
<LI><A HREF="#description">DESCRIPTION</A></LI>
<LI><A HREF="#example">EXAMPLE</A></LI>
<LI><A HREF="#see also">SEE ALSO</A></LI>
<LI><A HREF="#version">VERSION</A></LI>
<LI><A HREF="#author">AUTHOR</A></LI>
<LI><A HREF="#copyright">COPYRIGHT</A></LI>
<LI><A HREF="#license agreement">LICENSE AGREEMENT</A></LI>
</UL>
<!-- INDEX END -->
<HR>
<P>
<H1><A NAME="name">NAME</A></H1>
<P>Bit::ShiftReg - Bit Shift Registers with Rotate / Shift Operations</P>
<P>Implements rotate left, rotate right, shift left and shift right
operations with carry flag for all C integer types</P>
<P>
<HR>
<H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
<UL>
<LI>Linux</LI>
<LI>Solaris</LI>
<LI>Windows</LI>
</UL>
<HR>
<H1><A NAME="synopsis">SYNOPSIS</A></H1>
<UL>
<LI>
<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>
<CODE>LSB_byte MSB_byte LSB_short MSB_short LSB_int MSB_int LSB_long MSB_long</CODE>
<CODE>ROL_byte ROR_byte SHL_byte SHR_byte ROL_short ROR_short SHL_short SHR_short</CODE>
<CODE>ROL_int ROR_int SHL_int SHR_int ROL_long ROR_long SHL_long SHR_long );</CODE>
<P>imports all (or some, by leaving some out) of the available operations
and functions</P>
<P></P>
<LI>
<A HREF="../../../lib/Pod/perlfunc.html#item_qw"><CODE>use Bit::ShiftReg qw(:all);</CODE></A>
<P>imports all available operations and functions</P>
<P></P>
<LI>
<CODE>$version = Bit::ShiftReg::Version();</CODE>
<P>returns the module's version number</P>
<P></P>
<LI>
<CODE>$bits = bits_of_byte();</CODE>
<P>returns the number of bits in a byte (unsigned char) on your machine</P>
<P></P>
<LI>
<CODE>$bits = bits_of_short();</CODE>
<P>returns the number of bits in an unsigned short on your machine</P>
<P></P>
<LI>
<CODE>$bits = bits_of_int();</CODE>
<P>returns the number of bits in an unsigned int on your machine</P>
<P></P>
<LI>
<CODE>$bits = bits_of_long();</CODE>
<P>returns the number of bits in an unsigned long on your machine</P>
<P></P>
<LI>
<CODE>$lsb = LSB_byte($value);</CODE>
<P>returns the least significant bit (LSB) of a byte (unsigned char)</P>
<P></P>
<LI>
<CODE>$msb = MSB_byte($value);</CODE>
<P>returns the most significant bit (MSB) of a byte (unsigned char)</P>
<P></P>
<LI>
<CODE>$lsb = LSB_short($value);</CODE>
<P>returns the least significant bit (LSB) of an unsigned short</P>
<P></P>
<LI>
<CODE>$msb = MSB_short($value);</CODE>
<P>returns the most significant bit (MSB) of an unsigned short</P>
<P></P>
<LI>
<CODE>$lsb = LSB_int($value);</CODE>
<P>returns the least significant bit (LSB) of an unsigned int</P>
<P></P>
<LI>
<CODE>$msb = MSB_int($value);</CODE>
<P>returns the most significant bit (MSB) of an unsigned int</P>
<P></P>
<LI>
<CODE>$lsb = LSB_long($value);</CODE>
<P>returns the least significant bit (LSB) of an unsigned long</P>
<P></P>
<LI>
<CODE>$msb = MSB_long($value);</CODE>
<P>returns the most significant bit (MSB) of an unsigned long</P>
<P></P>
<LI>
<CODE>$carry = ROL_byte($value);</CODE>
<P></P>
<LI>
<CODE>$carry = ROR_byte($value);</CODE>
<P></P>
<LI>
<CODE>$carry_out = SHL_byte($value,$carry_in);</CODE>
<P></P>
<LI>
<CODE>$carry_out = SHR_byte($value,$carry_in);</CODE>
<P></P>
<LI>
<CODE>$carry = ROL_short($value);</CODE>
<P></P>
<LI>
<CODE>$carry = ROR_short($value);</CODE>
<P></P>
<LI>
<CODE>$carry_out = SHL_short($value,$carry_in);</CODE>
<P></P>
<LI>
<CODE>$carry_out = SHR_short($value,$carry_in);</CODE>
<P></P>
<LI>
<CODE>$carry = ROL_int($value);</CODE>
<P></P>
<LI>
<CODE>$carry = ROR_int($value);</CODE>
<P></P>
<LI>
<CODE>$carry_out = SHL_int($value,$carry_in);</CODE>
<P></P>
<LI>
<CODE>$carry_out = SHR_int($value,$carry_in);</CODE>
<P></P>
<LI>
<CODE>$carry = ROL_long($value);</CODE>
<P></P>
<LI>
<CODE>$carry = ROR_long($value);</CODE>
<P></P>
<LI>
<CODE>$carry_out = SHL_long($value,$carry_in);</CODE>
<P></P>
<LI>
<CODE>$carry_out = SHR_long($value,$carry_in);</CODE>
<P></P></UL>
<P><STRONG>Note that ``$value'' must be a variable in the calls of the functions</STRONG>
<STRONG>ROL, ROR, SHL and SHR, and that the contents of this variable are</STRONG>
<STRONG>altered IMPLICITLY by these functions!</STRONG></P>
<P><STRONG>Note also that the ``carry'' input value is always truncated to the least</STRONG>
<STRONG>significant bit, i.e., input values for ``carry'' must be either 0 or 1!</STRONG></P>
<P><STRONG>Finally, note that the return values of the functions LSB, MSB, ROL, ROR,</STRONG>
<STRONG>SHL and SHR are always either 0 or 1!</STRONG></P>
<P>
<HR>
<H1><A NAME="description">DESCRIPTION</A></H1>
<P>This module implements rotate left, rotate right, shift left and shift
right operations with carry flag for all C integer types.</P>
<P>The results depend on the number of bits that the integer types unsigned
char, unsigned short, unsigned int and unsigned long have on your machine.</P>
<P>The module automatically determines the number of bits of each integer type
and adjusts its internal constants accordingly.</P>
<P>How the operations work:</P>
<DL>
<DT><STRONG><A NAME="item_ROL">ROL</A></STRONG><BR>
<DD>
Rotate Left:
<PRE>
carry: value:</PRE>
<PRE>
+---+ +---+---+---+--- ---+---+---+---+
| 1 | <---+--- | 1 | 0 | 0 | 1 ... 1 | 0 | 1 | 1 | <---+
+---+ | +---+---+---+--- ---+---+---+---+ |
| |
+------------------------------------------------+</PRE>
<P></P>
<DT><STRONG><A NAME="item_ROR">ROR</A></STRONG><BR>
<DD>
Rotate Right:
<PRE>
value: carry:</PRE>
<PRE>
+---+---+---+--- ---+---+---+---+ +---+
+---> | 1 | 0 | 0 | 1 ... 1 | 0 | 1 | 1 | ---+---> | 1 |
| +---+---+---+--- ---+---+---+---+ | +---+
| |
+------------------------------------------------+</PRE>
<P></P>
<DT><STRONG><A NAME="item_SHL">SHL</A></STRONG><BR>
<DD>
Shift Left:
<PRE>
carry value: carry
out: in:
+---+ +---+---+---+--- ---+---+---+---+ +---+
| 1 | <--- | 1 | 0 | 0 | 1 ... 1 | 0 | 1 | 1 | <--- | 1 |
+---+ +---+---+---+--- ---+---+---+---+ +---+</PRE>
<P></P>
<DT><STRONG><A NAME="item_SHR">SHR</A></STRONG><BR>
<DD>
Shift Right:
<PRE>
carry value: carry
in: out:
+---+ +---+---+---+--- ---+---+---+---+ +---+
| 1 | ---> | 1 | 0 | 0 | 1 ... 1 | 0 | 1 | 1 | ---> | 1 |
+---+ +---+---+---+--- ---+---+---+---+ +---+</PRE>
<P></P></DL>
<P>
<HR>
<H1><A NAME="example">EXAMPLE</A></H1>
<P>Suppose you want to implement shift registers in a machine-independent
way.</P>
<P>The only C integer type whose length in bits you can be pretty sure about
is probably a byte, since the C standard only prescribes minimum lengths
for char, short, int and long and that <CODE>sizeof(char)</CODE> <CODE><=</CODE>
<CODE>sizeof(short)</CODE> <CODE><=</CODE> <CODE>sizeof(int)</CODE> <CODE><=</CODE> <CODE>sizeof(long)</CODE>.</P>
<P>How to implement a 4-byte shift register and the 4 operations ROL, ROR,
SHL and SHR on it:</P>
<P>First, you need to define 4 byte registers:</P>
<PRE>
$byte0 = 0;
$byte1 = 0;
$byte2 = 0;
$byte3 = 0;</PRE>
<P>Then proceed as follows:</P>
<DL>
<DT><STRONG>ROL</STRONG><BR>
<DD>
Rotate left:
<PRE>
$carry = SHL_byte($byte3, SHL_byte($byte2, SHL_byte($byte1,
SHL_byte($byte0, MSB_byte($byte3)))));</PRE>
<P></P>
<DT><STRONG>ROR</STRONG><BR>
<DD>
Rotate right:
<PRE>
$carry = SHR_byte($byte0, SHR_byte($byte1, SHR_byte($byte2,
SHR_byte($byte3, LSB_byte($byte0)))));</PRE>
<P></P>
<DT><STRONG>SHL</STRONG><BR>
<DD>
Shift left:
<PRE>
$carry_out = SHL_byte($byte3, SHL_byte($byte2, SHL_byte($byte1,
SHL_byte($byte0, $carry_in))));</PRE>
<P></P>
<DT><STRONG>SHR</STRONG><BR>
<DD>
Shift right:
<PRE>
$carry_out = SHR_byte($byte0, SHR_byte($byte1, SHR_byte($byte2,
SHR_byte($byte3, $carry_in))));</PRE>
<P></P></DL>
<P>
<HR>
<H1><A NAME="see also">SEE ALSO</A></H1>
<P>perl(1), perlsub(1), perlmod(1), perlxs(1), perlxstut(1), perlguts(1).</P>
<P>
<HR>
<H1><A NAME="version">VERSION</A></H1>
<P>This man page documents Bit::ShiftReg version 2.0.</P>
<P>
<HR>
<H1><A NAME="author">AUTHOR</A></H1>
<P>Steffen Beyer <<A HREF="mailto:sb@sdm.de">sb@sdm.de</A>>.</P>
<P>
<HR>
<H1><A NAME="copyright">COPYRIGHT</A></H1>
<P>Copyright (c) 1997 by Steffen Beyer. All rights reserved.</P>
<P>
<HR>
<H1><A NAME="license agreement">LICENSE AGREEMENT</A></H1>
<P>This package is free software; you can redistribute it
and/or modify it under the same terms as Perl itself.</P>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> Bit::ShiftReg - Bit Shift Registers with Rotate / Shift Operations</P></STRONG>
</TD></TR>
</TABLE>
</BODY>
</HTML>