README.md (1997B)
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 # toUint32 22 23 > Convert a signed 32-bit integer to an unsigned 32-bit integer. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var int32ToUint32 = require( '@stdlib/number/int32/base/to-uint32' ); 31 ``` 32 33 #### int32ToUint32( x ) 34 35 Converts a signed 32-bit integer to an unsigned 32-bit integer. 36 37 ```javascript 38 var float64ToInt32 = require( '@stdlib/number/float64/base/to-int32' ); 39 40 var y = int32ToUint32( float64ToInt32( -1 ) ); 41 // returns 4294967295 42 43 y = int32ToUint32( float64ToInt32( 3 ) ); 44 // returns 3 45 ``` 46 47 </section> 48 49 <!-- /.usage --> 50 51 <section class="examples"> 52 53 ## Examples 54 55 <!-- eslint no-undef: "error" --> 56 57 ```javascript 58 var randu = require( '@stdlib/random/base/randu' ); 59 var MAX_INT32 = require( '@stdlib/constants/int32/max' ); 60 var float64ToInt32 = require( '@stdlib/number/float64/base/to-int32' ); 61 var int32ToUint32 = require( '@stdlib/number/int32/base/to-uint32' ); 62 63 var uint32; 64 var int32; 65 var sign; 66 var i; 67 68 for ( i = 0; i < 100; i++ ) { 69 if ( randu() < 0.5 ) { 70 sign = -1.0; 71 } else { 72 sign = 1.0; 73 } 74 // Generate a random signed 32-bit integer: 75 int32 = float64ToInt32( sign*randu()*MAX_INT32 ); 76 77 // Convert the signed integer to an unsigned 32-bit integer: 78 uint32 = int32ToUint32( int32 ); 79 80 console.log( 'int32: %d => uint32: %d', int32, uint32 ); 81 } 82 ``` 83 84 </section> 85 86 <!-- /.examples --> 87 88 <section class="links"> 89 90 </section> 91 92 <!-- /.links -->