time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (2524B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2018 The Stdlib Authors.
      6 
      7 Licensed under the Apache License, Version 2.0 (the "License");
      8 you may not use this file except in compliance with the License.
      9 You may obtain a copy of the License at
     10 
     11    http://www.apache.org/licenses/LICENSE-2.0
     12 
     13 Unless required by applicable law or agreed to in writing, software
     14 distributed under the License is distributed on an "AS IS" BASIS,
     15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 See the License for the specific language governing permissions and
     17 limitations under the License.
     18 
     19 -->
     20 
     21 # Bitwise Rotation
     22 
     23 > Bitwise rotation to the left.
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var rotl32 = require( '@stdlib/number/uint32/base/rotl' );
     31 ```
     32 
     33 #### rotl32( x, shift )
     34 
     35 Performs a bitwise rotation to the left.
     36 
     37 ```javascript
     38 var toBinaryStringUint32 = require( '@stdlib/number/uint32/base/to-binary-string' );
     39 
     40 var x = 2147483649;
     41 var bstr = toBinaryStringUint32( x );
     42 // returns '10000000000000000000000000000001'
     43 
     44 var y = rotl32( x, 10 );
     45 // returns 1536
     46 
     47 bstr = toBinaryStringUint32( y );
     48 // returns '00000000000000000000011000000000'
     49 ```
     50 
     51 </section>
     52 
     53 <!-- /.usage -->
     54 
     55 <section class="notes">
     56 
     57 ## Notes
     58 
     59 -   If provided a `shift` equal to `0`, the function returns the input value.
     60 
     61     ```javascript
     62     var y = rotl32( 3, 0 );
     63     // returns 3
     64     ```
     65 
     66 -   If provided a `shift` greater than `31`, the function performs a bitwise rotation based on the `5` least significant bits of `shift` (i.e., `shift % 32`).
     67 
     68     ```javascript
     69     var shift = 34; // 00000000000000000000000000100010
     70 
     71     var y = rotl( 1, shift ); // 00000000000000000000000000000100
     72     // returns 4
     73     ```
     74 
     75 </section>
     76 
     77 <!-- /.notes -->
     78 
     79 <section class="examples">
     80 
     81 ## Examples
     82 
     83 <!-- eslint no-undef: "error" -->
     84 
     85 ```javascript
     86 var toBinaryStringUint32 = require( '@stdlib/number/uint32/base/to-binary-string' );
     87 var MAX_INT = require( '@stdlib/constants/uint32/max' );
     88 var rotl32 = require( '@stdlib/number/uint32/base/rotl' );
     89 
     90 var HALF;
     91 var x;
     92 var y;
     93 var i;
     94 
     95 for ( i = 0; i < 100; i++ ) {
     96     x = i;
     97     y = rotl32( x, 10 );
     98     console.log( '%d => %s => %s => %d', x, toBinaryStringUint32( x ), toBinaryStringUint32( y ), y );
     99 }
    100 
    101 HALF = (MAX_INT+1) / 2;
    102 for ( i = 0; i < 100; i++ ) {
    103     x = HALF + i;
    104     y = rotl32( x, 10 );
    105     console.log( '%d => %s => %s => %d', x, toBinaryStringUint32( x ), toBinaryStringUint32( y ), y );
    106 }
    107 ```
    108 
    109 </section>
    110 
    111 <!-- /.examples -->
    112 
    113 <section class="links">
    114 
    115 </section>
    116 
    117 <!-- /.links -->