<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Class: Integer</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" /> <script type="text/javascript"> // <![CDATA[ function popupCode( url ) { window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400") } function toggleCode( id ) { if ( document.getElementById ) elem = document.getElementById( id ); else if ( document.all ) elem = eval( "document.all." + id ); else return false; elemStyle = elem.style; if ( elemStyle.display != "block" ) { elemStyle.display = "block" } else { elemStyle.display = "none" } return true; } // Make codeblocks hidden by default document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" ) // ]]> </script> </head> <body> <div id="classHeader"> <table class="header-table"> <tr class="top-aligned-row"> <td><strong>Class</strong></td> <td class="class-name-in-header">Integer</td> </tr> <tr class="top-aligned-row"> <td><strong>In:</strong></td> <td> <a href="../files/lib/ruby-vpi/integer_rb.html"> lib/ruby-vpi/integer.rb </a> <br /> </td> </tr> <tr class="top-aligned-row"> <td><strong>Parent:</strong></td> <td> <a href="Object.html"> Object </a> </td> </tr> </table> </div> <!-- banner header --> <div id="bodyContent"> <div id="contextContent"> <div id="description"> <p> NOTE: Because integers are <em>immediate</em> values in Ruby, these methods <b>cannot</b> modify the value of the integer upon which they are invoked. Instead, they return the new value as their result. </p> </div> </div> <div id="method-list"> <h3 class="section-bar">Methods</h3> <div class="name-list"> <a href="#M000019">extend_sign</a> <a href="#M000010">length</a> <a href="#M000011">limit</a> <a href="#M000009">log2</a> <a href="#M000013">mask</a> <a href="#M000015">max</a> <a href="#M000017">pack</a> <a href="#M000020">split</a> <a href="#M000012">to_limit</a> <a href="#M000014">to_mask</a> <a href="#M000016">to_max</a> <a href="#M000018">unpack</a> </div> </div> </div> <!-- if includes --> <div id="section"> <!-- if method_list --> <div id="methods"> <h3 class="section-bar">Public Instance methods</h3> <div id="method-M000019" class="method-detail"> <a name="M000019"></a> <div class="method-heading"> <a href="Integer.src/M000019.html" target="Code" class="method-signature" onclick="popupCode('Integer.src/M000019.html');return false;"> <span class="method-name">extend_sign</span><span class="method-args">(aOrigWidth, aExtWidth)</span> </a> </div> <div class="method-description"> <p> Performs sign extension on this integer, which has the given width (number of bits), so that the result will have the given extended width (number of bits). </p> </div> </div> <div id="method-M000010" class="method-detail"> <a name="M000010"></a> <div class="method-heading"> <a href="Integer.src/M000010.html" target="Code" class="method-signature" onclick="popupCode('Integer.src/M000010.html');return false;"> <span class="method-name">length</span><span class="method-args">()</span> </a> </div> <div class="method-description"> <p> Returns the minimum number of bits necessary to represent this integer. </p> </div> </div> <div id="method-M000011" class="method-detail"> <a name="M000011"></a> <div class="method-heading"> <a href="Integer.src/M000011.html" target="Code" class="method-signature" onclick="popupCode('Integer.src/M000011.html');return false;"> <span class="method-name">limit</span><span class="method-args">()</span> </a> </div> <div class="method-description"> <p> Returns the lowest upper-bound of this integer. This integer cannot reach the <a href="Integer.html#M000011">limit</a> without occupying more bits in its binary representation. </p> </div> </div> <div id="method-M000009" class="method-detail"> <a name="M000009"></a> <div class="method-heading"> <a href="Integer.src/M000009.html" target="Code" class="method-signature" onclick="popupCode('Integer.src/M000009.html');return false;"> <span class="method-name">log2</span><span class="method-args">()</span> </a> </div> <div class="method-description"> <p> Returns the ceiling of the logarithm (base 2) of this positive integer. </p> </div> </div> <div id="method-M000013" class="method-detail"> <a name="M000013"></a> <div class="method-heading"> <a href="Integer.src/M000013.html" target="Code" class="method-signature" onclick="popupCode('Integer.src/M000013.html');return false;"> <span class="method-name">mask</span><span class="method-args">()</span> </a> </div> <div class="method-description"> <p> Returns a bit-<a href="Integer.html#M000013">mask</a> capable of masking this integer. </p> </div> </div> <div id="method-M000015" class="method-detail"> <a name="M000015"></a> <div class="method-heading"> <span class="method-name">max</span><span class="method-args">()</span> </div> <div class="method-description"> <p> Alias for <a href="Integer.html#M000013">mask</a> </p> </div> </div> <div id="method-M000017" class="method-detail"> <a name="M000017"></a> <div class="method-heading"> <a href="Integer.src/M000017.html" target="Code" class="method-signature" onclick="popupCode('Integer.src/M000017.html');return false;"> <span class="method-name">pack</span><span class="method-args">(aPackedWidth)</span> </a> </div> <div class="method-description"> <p> Transforms this infinite-<a href="Integer.html#M000010">length</a> Ruby integer into a fixed-<a href="Integer.html#M000010">length</a> integer (represented in two‘s complement form) that has the given width (number of bits). </p> </div> </div> <div id="method-M000020" class="method-detail"> <a name="M000020"></a> <div class="method-heading"> <a href="Integer.src/M000020.html" target="Code" class="method-signature" onclick="popupCode('Integer.src/M000020.html');return false;"> <span class="method-name">split</span><span class="method-args">(aWidth = 8)</span> </a> </div> <div class="method-description"> <p> Splits this integer into an array of smaller integers, each of which have the given positive, non-zero width (number of bits). These smaller integers are ordered from left to right, in the same way that humans write unsigned binary numbers; for example: </p> <pre> >> 6.split 1 => [1, 1, 0] >> 6.split(1).map {|i| i.to_s 2} => ["1", "1", "0"] >> 6.split 2 => [1, 2] >> 6.split(2).map {|i| i.to_s 2} => ["1", "10"] </pre> </div> </div> <div id="method-M000012" class="method-detail"> <a name="M000012"></a> <div class="method-heading"> <a href="Integer.src/M000012.html" target="Code" class="method-signature" onclick="popupCode('Integer.src/M000012.html');return false;"> <span class="method-name">to_limit</span><span class="method-args">()</span> </a> </div> <div class="method-description"> <p> Returns the lowest upper-bound of an integer with <b>this</b> number of bits. </p> </div> </div> <div id="method-M000014" class="method-detail"> <a name="M000014"></a> <div class="method-heading"> <a href="Integer.src/M000014.html" target="Code" class="method-signature" onclick="popupCode('Integer.src/M000014.html');return false;"> <span class="method-name">to_mask</span><span class="method-args">()</span> </a> </div> <div class="method-description"> <p> Returns a bit-<a href="Integer.html#M000013">mask</a> capable of masking an integer with <b>this</b> number of bits. </p> </div> </div> <div id="method-M000016" class="method-detail"> <a name="M000016"></a> <div class="method-heading"> <span class="method-name">to_max</span><span class="method-args">()</span> </div> <div class="method-description"> <p> Alias for <a href="Integer.html#M000014">to_mask</a> </p> </div> </div> <div id="method-M000018" class="method-detail"> <a name="M000018"></a> <div class="method-heading"> <a href="Integer.src/M000018.html" target="Code" class="method-signature" onclick="popupCode('Integer.src/M000018.html');return false;"> <span class="method-name">unpack</span><span class="method-args">(aPackedWidth)</span> </a> </div> <div class="method-description"> <p> Transforms this fixed-<a href="Integer.html#M000010">length</a> integer (represented in two‘s complement form) that has the given width (number of bits) into an infinite-<a href="Integer.html#M000010">length</a> Ruby integer. </p> </div> </div> </div> </div> <div id="validator-badges"> <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p> </div> </body> </html>