README.md (2101B)
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 # From Binary String 22 23 > Create an unsigned 8-bit integer from a [literal bit representation][@stdlib/number/uint8/base/to-binary-string]. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var fromBinaryStringUint8 = require( '@stdlib/number/uint8/base/from-binary-string' ); 31 ``` 32 33 #### fromBinaryStringUint8( bstr ) 34 35 Creates an unsigned 8-bit integer from a [literal bit representation][@stdlib/number/uint8/base/to-binary-string]. 36 37 ```javascript 38 var bstr = '01010101'; 39 var val = fromBinaryStringUint8( bstr ); 40 // returns 85 41 42 bstr = '00000000'; 43 val = fromBinaryStringUint8( bstr ); 44 // returns 0 45 46 bstr = '00000010'; 47 val = fromBinaryStringUint8( bstr ); 48 // returns 2 49 50 bstr = '11111111'; 51 val = fromBinaryStringUint8( bstr ); 52 // returns 255 53 ``` 54 55 </section> 56 57 <!-- /.usage --> 58 59 <section class="examples"> 60 61 ## Examples 62 63 <!-- eslint no-undef: "error" --> 64 65 ```javascript 66 var toBinaryStringUint8 = require( '@stdlib/number/uint8/base/to-binary-string' ); 67 var fromBinaryStringUint8 = require( '@stdlib/number/uint8/base/from-binary-string' ); 68 69 var b; 70 var y; 71 var i; 72 73 // Convert integers to literal bit representations and then convert them back... 74 for ( i = 0; i < 256; i++ ) { 75 b = toBinaryStringUint8( i ); 76 y = fromBinaryStringUint8( b ); 77 console.log( '%d => %s => %d', i, b, y ); 78 } 79 ``` 80 81 </section> 82 83 <!-- /.examples --> 84 85 <section class="links"> 86 87 [@stdlib/number/uint8/base/to-binary-string]: https://www.npmjs.com/package/@stdlib/number/tree/main/uint8/base/to-binary-string 88 89 </section> 90 91 <!-- /.links -->