Skip to content
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@license Apache-2.0

Copyright (c) 2018 The Stdlib Authors.
Copyright (c) 2024 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -59,6 +59,7 @@ val = fromBinaryStringUint32( bstr );
<section class="examples">

## Examples
Here are some examples demonstrating the usage of the fromBinaryStringUint32 function:

<!-- eslint no-undef: "error" -->

Expand All @@ -69,17 +70,22 @@ var MAX_UINT = require( '@stdlib/constants/uint32/max' );
var toBinaryStringUint32 = require( '@stdlib/number/uint32/base/to-binary-string' );
var fromBinaryStringUint32 = require( '@stdlib/number/uint32/base/from-binary-string' );

var b;
var x;
var y;
var i;
var b;

// Example 1: Convert a binary string representing an integer to a 32-bit unsigned integer
b = '10101010101010101010101010101010';
y = fromBinaryStringUint32( binaryString );
// returns 2863311530

// Example 2: Convert random integers to binary strings and then back to integers

// Convert random integers to literal bit representations and then convert them back...
for ( i = 0; i < 100; i++ ) {
x = round( randu()*MAX_UINT );
for ( var i = 0; i < 5; i++ ) {
x = round( randu * MAX_UINT );
b = toBinaryStringUint32( x );
y = fromBinaryStringUint32( b );
console.log( '%d => %s => %d', x, b, y );
y = fromBinaryStringUint32( y );
console.log( '%d => %s => %d', x, b, y);
}
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,17 +22,22 @@ var randu = require( '@stdlib/random/base/randu' );
var round = require( '@stdlib/math/base/special/round' );
var MAX_UINT = require( '@stdlib/constants/uint32/max' );
var toBinaryStringUint32 = require( '@stdlib/number/uint32/base/to-binary-string' );
var fromBinaryStringUint32 = require( './../lib' );
var fromBinaryStringUint32 = require( '@stdlib/number/uint32/base/from-binary-string' );

var b;
var x;
var y;
var i;
var b;

// Example 1: Convert a binary string representing an integer to a 32-bit unsigned integer
b = '10101010101010101010101010101010';
y = fromBinaryStringUint32( binaryString );
// returns 2863311530

// Example 2: Convert random integers to binary strings and then back to integers

// Convert random integers to literal bit representations and then convert them back...
for ( i = 0; i < 100; i++ ) {
x = round( randu()*MAX_UINT );
b = toBinaryStringUint32( x );
y = fromBinaryStringUint32( b );
console.log( '%d => %s => %d', x, b, y );
for ( var i = 0; i < 5; i++ ) {
x = round( randu * MAX_UINT );
b = toBinaryStringUint32( x );
y = fromBinaryStringUint32( y );
console.log( '%d => %s => %d', x, b, y);
}
34 changes: 20 additions & 14 deletions lib/node_modules/@stdlib/number/uint32/base/rotl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@license Apache-2.0

Copyright (c) 2018 The Stdlib Authors.
Copyright (c) 2024 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -83,27 +83,33 @@ bstr = toBinaryStringUint32( y );
<!-- eslint no-undef: "error" -->

```javascript
var toBinaryStringUint32 = require( '@stdlib/number/uint32/base/to-binary-string' );
var MAX_INT = require( '@stdlib/constants/uint32/max' );
var rotl32 = require( '@stdlib/number/uint32/base/rotl' );
var toBinaryStringUint32 = require('@stdlib/number/uint32/base/to-binary-string');
var MAX_UINT = require('@stdlib/constants/uint32/max');
var rotl32 = require('@stdlib/number/uint32/base/rotl');

var HALF;
var x;
var y;
var i;

for ( i = 0; i < 100; i++ ) {
var rotationAmount;
// Example 1: Rotate integers to the left and display their binary representations
for (var i = 0; i < 100; i++) {
x = i;
y = rotl32( x, 10 );
console.log( '%d => %s => %s => %d', x, toBinaryStringUint32( x ), toBinaryStringUint32( y ), y );
y = rotl32(x, 10);
console.log('%d => %s => %s => %d', x, toBinaryStringUint32(x), toBinaryStringUint32(y), y);
}

HALF = (MAX_INT+1) / 2;
for ( i = 0; i < 100; i++ ) {
// Example 2: Rotate integers in the second half of the range to the left and display their binary representations
var HALF = (MAX_UINT + 1) / 2;
for (var i = 0; i < 100; i++) {
x = HALF + i;
y = rotl32( x, 10 );
console.log( '%d => %s => %s => %d', x, toBinaryStringUint32( x ), toBinaryStringUint32( y ), y );
y = rotl32(x, 10);
console.log('%d => %s => %s => %d', x, toBinaryStringUint32(x), toBinaryStringUint32(y), y);
}

// Example 3: Rotate a specific integer and display its binary representation
var x = 123456;
var rotationAmount = 5;
var y = rotl32(x, rotationAmount);
console.log('%d => %d: %s => %s', x, rotationAmount, toBinaryStringUint32(x), toBinaryStringUint32(y));
```

</section>
Expand Down
38 changes: 22 additions & 16 deletions lib/node_modules/@stdlib/number/uint32/base/rotl/examples/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,24 +18,30 @@

'use strict';

var toBinaryStringUint32 = require( '@stdlib/number/uint32/base/to-binary-string' );
var MAX_INT = require( '@stdlib/constants/uint32/max' );
var rotl32 = require( './../lib' );
var toBinaryStringUint32 = require('@stdlib/number/uint32/base/to-binary-string');
var MAX_UINT = require('@stdlib/constants/uint32/max');
var rotl32 = require('@stdlib/number/uint32/base/rotl');

var HALF;
var x;
var y;
var i;

for ( i = 0; i < 100; i++ ) {
x = i;
y = rotl32( x, 10 );
console.log( '%d => %s => %s => %d', x, toBinaryStringUint32( x ), toBinaryStringUint32( y ), y );
var rotationAmount;
// Example 1: Rotate integers to the left and display their binary representations
for (var i = 0; i < 100; i++) {
x = i;
y = rotl32(x, 10);
console.log('%d => %s => %s => %d', x, toBinaryStringUint32(x), toBinaryStringUint32(y), y);
}

HALF = (MAX_INT+1) / 2;
for ( i = 0; i < 100; i++ ) {
x = HALF + i;
y = rotl32( x, 10 );
console.log( '%d => %s => %s => %d', x, toBinaryStringUint32( x ), toBinaryStringUint32( y ), y );
// Example 2: Rotate integers in the second half of the range to the left and display their binary representations
var HALF = (MAX_UINT + 1) / 2;
for (var i = 0; i < 100; i++) {
x = HALF + i;
y = rotl32(x, 10);
console.log('%d => %s => %s => %d', x, toBinaryStringUint32(x), toBinaryStringUint32(y), y);
}

// Example 3: Rotate a specific integer and display its binary representation
var x = 123456;
var rotationAmount = 5;
var y = rotl32(x, rotationAmount);
console.log('%d => %d: %s => %s', x, rotationAmount, toBinaryStringUint32(x), toBinaryStringUint32(y));
33 changes: 20 additions & 13 deletions lib/node_modules/@stdlib/number/uint32/base/rotr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@license Apache-2.0

Copyright (c) 2018 The Stdlib Authors.
Copyright (c) 2024 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -83,27 +83,34 @@ bstr = toBinaryStringUint32( y );
<!-- eslint no-undef: "error" -->

```javascript
var toBinaryStringUint32 = require( '@stdlib/number/uint32/base/to-binary-string' );
var MAX_INT = require( '@stdlib/constants/uint32/max' );
var rotr32 = require( '@stdlib/number/uint32/base/rotr' );
var toBinaryStringUint32 = require('@stdlib/number/uint32/base/to-binary-string');
var MAX_UINT = require('@stdlib/constants/uint32/max');
var rotr32 = require('@stdlib/number/uint32/base/rotr');

var HALF;
var x;
var y;
var i;
var rotationAmount;

for ( i = 0; i < 100; i++ ) {
// Example 1: Rotate integers to the right and display their binary representations
for (var i = 0; i < 100; i++) {
x = i;
y = rotr32( x, 10 );
console.log( '%d => %s => %s => %d', x, toBinaryStringUint32( x ), toBinaryStringUint32( y ), y );
y = rotr32(x, 10);
console.log('%d => %s => %s => %d', x, toBinaryStringUint32(x), toBinaryStringUint32(y), y);
}

HALF = (MAX_INT+1) / 2;
for ( i = 0; i < 100; i++ ) {
// Example 2: Rotate integers in the second half of the range to the right and display their binary representations
var HALF = (MAX_UINT + 1) / 2;
for (var i = 0; i < 100; i++) {
x = HALF + i;
y = rotr32( x, 10 );
console.log( '%d => %s => %s => %d', x, toBinaryStringUint32( x ), toBinaryStringUint32( y ), y );
y = rotr32(x, 10);
console.log('%d => %s => %s => %d', x, toBinaryStringUint32(x), toBinaryStringUint32(y), y);
}

// Example 3: Rotate a specific integer to the right and display its binary representation
var x = 123456;
var rotationAmount = 5;
var y = rotr32(x, rotationAmount);
console.log('%d => %d : %s => %s', x, rotationAmount, toBinaryStringUint32(x), toBinaryStringUint32(y));
```

</section>
Expand Down
37 changes: 22 additions & 15 deletions lib/node_modules/@stdlib/number/uint32/base/rotr/examples/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,24 +18,31 @@

'use strict';

var toBinaryStringUint32 = require( '@stdlib/number/uint32/base/to-binary-string' );
var MAX_INT = require( '@stdlib/constants/uint32/max' );
var rotr32 = require( './../lib' );
var toBinaryStringUint32 = require('@stdlib/number/uint32/base/to-binary-string');
var MAX_UINT = require('@stdlib/constants/uint32/max');
var rotr32 = require('@stdlib/number/uint32/base/rotr');

var HALF;
var x;
var y;
var i;
var rotationAmount;

for ( i = 0; i < 100; i++ ) {
x = i;
y = rotr32( x, 10 );
console.log( '%d => %s => %s => %d', x, toBinaryStringUint32( x ), toBinaryStringUint32( y ), y );
// Example 1: Rotate integers to the right and display their binary representations
for (var i = 0; i < 100; i++) {
x = i;
y = rotr32(x, 10);
console.log('%d => %s => %s => %d', x, toBinaryStringUint32(x), toBinaryStringUint32(y), y);
}

HALF = (MAX_INT+1) / 2;
for ( i = 0; i < 100; i++ ) {
x = HALF + i;
y = rotr32( x, 10 );
console.log( '%d => %s => %s => %d', x, toBinaryStringUint32( x ), toBinaryStringUint32( y ), y );
// Example 2: Rotate integers in the second half of the range to the right and display their binary representations
var HALF = (MAX_UINT + 1) / 2;
for (var i = 0; i < 100; i++) {
x = HALF + i;
y = rotr32(x, 10);
console.log('%d => %s => %s => %d', x, toBinaryStringUint32(x), toBinaryStringUint32(y), y);
}

// Example 3: Rotate a specific integer to the right and display its binary representation
var x = 123456;
var rotationAmount = 5;
var y = rotr32(x, rotationAmount);
console.log('%d => %d : %s => %s', x, rotationAmount, toBinaryStringUint32(x), toBinaryStringUint32(y));
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@license Apache-2.0

Copyright (c) 2018 The Stdlib Authors.
Copyright (c) 2024 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -84,27 +84,36 @@ str = toBinaryString( a[2] );
<!-- eslint no-undef: "error" -->

```javascript
var randu = require( '@stdlib/random/base/randu' );
var round = require( '@stdlib/math/base/special/round' );
var Uint32Array = require( '@stdlib/array/uint32' );
var toBinaryString = require( '@stdlib/number/uint32/base/to-binary-string' );
var randu = require('@stdlib/random/base/randu');
var round = require('@stdlib/math/base/special/round');
var Uint32Array = require('@stdlib/array/uint32');
var toBinaryString = require('@stdlib/number/uint32/base/to-binary-string');

var x;
var y;
var b;
var i;
var specificIntegers;

// Example 1: Generate random unsigned 32-bit integers and convert them to literal bit representations
var numberOfIntegers = 100;
var integers = new Uint32Array(numberOfIntegers);

for (var i = 0; i < numberOfIntegers; i++) {
integers[i] = round(randu() * 1.0e5);
}

// Generate random unsigned 32-bit integers...
x = new Uint32Array( 100 );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = round( randu()*1.0e5 );
for (var i = 0; i < numberOfIntegers; i++) {
b = toBinaryString(integers[i]);
y = parseInt(b, 2);
console.log('Integer: %d, Binary Representation: %s, Parsed Integer: %d', integers[i], b, y);
}

// Convert unsigned 32-bit integers to literal bit representations...
for ( i = 0; i < x.length; i++ ) {
b = toBinaryString( x[i] );
y = parseInt( b, 2 );
console.log( 'x: %d, b: %s, y: %d', x[i], b, y );
// Example 2: Convert specific integers to literal bit representations
specificIntegers = [123, 456, 789, 1024];
for (var i = 0; i < specificIntegers.length; i++) {
b = toBinaryString(specificIntegers[i]);
y = parseInt(b, 2);
console.log('%d => %s => %d', specificIntegers[i], b, y);
}
```

Expand Down
Loading