README.md (4391B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2020 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 # Byte Order 22 23 > Platform [byte order][endianness]. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var BYTE_ORDER = require( '@stdlib/os/byte-order' ); 31 ``` 32 33 #### BYTE_ORDER 34 35 Platform byte order. 36 37 ```javascript 38 console.log( BYTE_ORDER ); 39 // => <string> 40 ``` 41 42 </section> 43 44 <!-- /.usage --> 45 46 <section class="notes"> 47 48 ## Notes 49 50 - The following values are possible: 51 52 - `'little-endian'` 53 - `'big-endian'` 54 - `'mixed-endian'` (also known as "middle-endian") 55 - `'unknown'` 56 57 </section> 58 59 <!-- /.notes --> 60 61 <section class="examples"> 62 63 ## Examples 64 65 <!-- eslint no-undef: "error" --> 66 67 ```javascript 68 var BYTE_ORDER = require( '@stdlib/os/byte-order' ); 69 70 if ( BYTE_ORDER === 'little-endian' ) { 71 console.log( 'Least significant byte comes first...' ); 72 } else if ( BYTE_ORDER === 'big-endian' ) { 73 console.log( 'Most significant byte comes first...' ); 74 } else { 75 console.log( 'This is uncommon...' ); 76 } 77 ``` 78 79 </section> 80 81 <!-- /.examples --> 82 83 <!-- C interface documentation. --> 84 85 * * * 86 87 <section class="c"> 88 89 ## C APIs 90 91 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> 92 93 <section class="intro"> 94 95 </section> 96 97 <!-- /.intro --> 98 99 <!-- C usage documentation. --> 100 101 <section class="usage"> 102 103 ### Usage 104 105 ```c 106 #include "stdlib/os/byte_order.h" 107 ``` 108 109 #### STDLIB_OS_ORDER_LITTLE_ENDIAN 110 111 Macro for an arbitrary constant indicating little-endian order. 112 113 ```c 114 #if defined(STDLIB_OS_BYTE_ORDER) && STDLIB_OS_BYTE_ORDER == STDLIB_OS_ORDER_LITTLE_ENDIAN 115 116 // Do something for little-endian... 117 118 #endif 119 ``` 120 121 If compiled on an unrecognized/unsupported platform, the macro is **not** defined. 122 123 #### STDLIB_OS_ORDER_BIG_ENDIAN 124 125 Macro for an arbitrary constant indicating big-endian order. 126 127 ```c 128 #if defined(STDLIB_OS_BYTE_ORDER) && STDLIB_OS_BYTE_ORDER == STDLIB_OS_ORDER_BIG_ENDIAN 129 130 // Do something for big-endian... 131 132 #endif 133 ``` 134 135 If compiled on an unrecognized/unsupported platform, the macro is **not** defined. 136 137 #### STDLIB_OS_BYTE_ORDER 138 139 Macro which equals either `STDLIB_OS_ORDER_LITTLE_ENDIAN` or `STDLIB_OS_ORDER_BIG_ENDIAN` (or host defined) depending on the resolved platform byte order. 140 141 ```c 142 #if defined(STDLIB_OS_BYTE_ORDER) 143 144 #if STDLIB_OS_BYTE_ORDER == STDLIB_OS_ORDER_LITTLE_ENDIAN 145 146 // Do something for little-endian... 147 148 #elif STDLIB_OS_BYTE_ORDER == STDLIB_OS_ORDER_BIG_ENDIAN 149 150 // Do something for big-endian... 151 152 #endif 153 154 #endif 155 ``` 156 157 If compiled on an unrecognized/unsupported platform, the macro is **not** defined. 158 159 </section> 160 161 <!-- /.usage --> 162 163 <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 164 165 <section class="notes"> 166 167 </section> 168 169 <!-- /.notes --> 170 171 <!-- C API usage examples. --> 172 173 <section class="examples"> 174 175 ### Examples 176 177 ```c 178 #include "stdlib/os/byte_order.h" 179 #include <stdio.h> 180 181 int main() { 182 #if defined(STDLIB_OS_BYTE_ORDER) 183 #if STDLIB_OS_BYTE_ORDER == STDLIB_OS_ORDER_LITTLE_ENDIAN 184 printf( "Platform is little-endian...\n" ); 185 #elif STDLIB_OS_BYTE_ORDER == STDLIB_OS_ORDER_BIG_ENDIAN 186 printf( "Platform is big-endian...\n" ); 187 #else 188 printf( "Platform endianness is either mixed-endian or unknown...\n" ) 189 #endif 190 #endif 191 } 192 ``` 193 194 </section> 195 196 <!-- /.examples --> 197 198 </section> 199 200 <!-- /.c --> 201 202 * * * 203 204 <section class="cli"> 205 206 ## CLI 207 208 <section class="usage"> 209 210 ### Usage 211 212 ```text 213 Usage: byte-order [options] 214 215 Options: 216 217 -h, --help Print this message. 218 -V, --version Print the package version. 219 ``` 220 221 </section> 222 223 <!-- /.usage --> 224 225 <section class="examples"> 226 227 ### Examples 228 229 ```bash 230 $ byte-order 231 ``` 232 233 </section> 234 235 <!-- /.examples --> 236 237 </section> 238 239 <!-- /.cli --> 240 241 <section class="links"> 242 243 [endianness]: https://en.wikipedia.org/wiki/Endianness 244 245 </section> 246 247 <!-- /.links -->