Showing the changes to Source/Libraries/GSF.Core/BitExtensions.cs (1 of 628 files). Show all
Unified · Split
| @@ -0,0 +1,2894 @@ | |||
| 1 | //****************************************************************************************************** | ||
| 2 | // BitExtensions.cs - Gbtc | ||
| 3 | // | ||
| 4 | // Copyright © 2010, Grid Protection Alliance. All Rights Reserved. | ||
| 5 | // | ||
| 6 | // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See | ||
| 7 | // the NOTICE file distributed with this work for additional information regarding copyright ownership. | ||
| 8 | // The GPA licenses this file to you under the Eclipse Public License -v 1.0 (the "License"); you may | ||
| 9 | // not use this file except in compliance with the License. You may obtain a copy of the License at: | ||
| 10 | // | ||
| 11 | // http://www.opensource.org/licenses/eclipse-1.0.php | ||
| 12 | // | ||
| 13 | // Unless agreed to in writing, the subject software distributed under the License is distributed on an | ||
| 14 | // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the | ||
| 15 | // License for the specific language governing permissions and limitations. | ||
| 16 | // | ||
| 17 | // Code Modification History: | ||
| 18 | // ---------------------------------------------------------------------------------------------------- | ||
| 19 | // 01/25/2008 - J. Ritchie Carroll | ||
| 20 | // Initial version of source generated. | ||
| 21 | // 09/14/2009 - Stephen C. Wills | ||
| 22 | // Added new header and license agreement. | ||
| 23 | // 10/8/2012 - Danyelle Gilliam | ||
| 24 | // Modified Header | ||
| 25 | // | ||
| 26 | //****************************************************************************************************** | ||
| 27 | |||
| 28 | |||
| 29 | |||
| 30 | |||
| 31 | #region [ Contributor License Agreements ] | ||
| 32 | |||
| 33 | /**************************************************************************\ | ||
| 34 | Copyright © 2009 - J. Ritchie Carroll, Pinal C. Patel | ||
| 35 | All rights reserved. | ||
| 36 | |||
| 37 | Redistribution and use in source and binary forms, with or without | ||
| 38 | modification, are permitted provided that the following conditions | ||
| 39 | are met: | ||
| 40 | |||
| 41 | * Redistributions of source code must retain the above copyright | ||
| 42 | notice, this list of conditions and the following disclaimer. | ||
| 43 | |||
| 44 | * Redistributions in binary form must reproduce the above | ||
| 45 | copyright notice, this list of conditions and the following | ||
| 46 | disclaimer in the documentation and/or other materials provided | ||
| 47 | with the distribution. | ||
| 48 | |||
| 49 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY | ||
| 50 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 51 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 52 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
| 53 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 54 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 55 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| 56 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
| 57 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 58 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| 59 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 60 | |||
| 61 | \**************************************************************************/ | ||
| 62 | |||
| 63 | #endregion | ||
| 64 | |||
| 65 | using System; | ||
| 66 | |||
| 67 | namespace GSF | ||
| 68 | { | ||
| 69 | #region [ Enumerations ] | ||
| 70 | |||
| 71 | /// <summary> | ||
| 72 | /// Represents bits in a signed or unsigned integer value. | ||
| 73 | /// </summary> | ||
| 74 | [Flags(), CLSCompliant(false)] | ||
| 75 | public enum Bits : ulong | ||
| 76 | { | ||
| 77 | /// <summary>No bits set (0x0000000000000000)</summary> | ||
| 78 | Nil = 0x00000000, | ||
| 79 | |||
| 80 | // Byte 0, Bits 0-7 | ||
| 81 | |||
| 82 | /// <summary>Bit 00 (0x0000000000000001)</summary> | ||
| 83 | Bit00 = 0x00000001, // 00000001 = 1 | ||
| 84 | |||
| 85 | /// <summary>Bit 01 (0x0000000000000002)</summary> | ||
| 86 | Bit01 = Bit00 << 1, // 00000010 = 2 | ||
| 87 | |||
| 88 | /// <summary>Bit 02 (0x0000000000000004)</summary> | ||
| 89 | Bit02 = Bit01 << 1, // 00000100 = 4 | ||
| 90 | |||
| 91 | /// <summary>Bit 03 (0x0000000000000008)</summary> | ||
| 92 | Bit03 = Bit02 << 1, // 00001000 = 8 | ||
| 93 | |||
| 94 | /// <summary>Bit 04 (0x0000000000000010)</summary> | ||
| 95 | Bit04 = Bit03 << 1, // 00010000 = 16 | ||
| 96 | |||
| 97 | /// <summary>Bit 05 (0x0000000000000020)</summary> | ||
| 98 | Bit05 = Bit04 << 1, // 00100000 = 32 | ||
| 99 | |||
| 100 | /// <summary>Bit 06 (0x0000000000000040)</summary> | ||
| 101 | Bit06 = Bit05 << 1, // 01000000 = 64 | ||
| 102 | |||
| 103 | /// <summary>Bit 07 (0x0000000000000080)</summary> | ||
| 104 | Bit07 = Bit06 << 1, // 10000000 = 128 | ||
| 105 | |||
| 106 | // Byte 1, Bits 8-15 | ||
| 107 | |||
| 108 | /// <summary>Bit 08 (0x0000000000000100)</summary> | ||
| 109 | Bit08 = Bit07 << 1, | ||
| 110 | |||
| 111 | /// <summary>Bit 09 (0x0000000000000200)</summary> | ||
| 112 | Bit09 = Bit08 << 1, | ||
| 113 | |||
| 114 | /// <summary>Bit 10 (0x0000000000000400)</summary> | ||
| 115 | Bit10 = Bit09 << 1, | ||
| 116 | |||
| 117 | /// <summary>Bit 11 (0x0000000000000800)</summary> | ||
| 118 | Bit11 = Bit10 << 1, | ||
| 119 | |||
| 120 | /// <summary>Bit 12 (0x0000000000001000)</summary> | ||
| 121 | Bit12 = Bit11 << 1, | ||
| 122 | |||
| 123 | /// <summary>Bit 13 (0x0000000000002000)</summary> | ||
| 124 | Bit13 = Bit12 << 1, | ||
| 125 | |||
| 126 | /// <summary>Bit 14 (0x0000000000004000)</summary> | ||
| 127 | Bit14 = Bit13 << 1, | ||
| 128 | |||
| 129 | /// <summary>Bit 15 (0x0000000000008000)</summary> | ||
| 130 | Bit15 = Bit14 << 1, | ||
| 131 | |||
| 132 | // Byte 2, Bits 16-23 | ||
| 133 | |||
| 134 | /// <summary>Bit 16 (0x0000000000010000)</summary> | ||
| 135 | Bit16 = Bit15 << 1, | ||
| 136 | |||
| 137 | /// <summary>Bit 17 (0x0000000000020000)</summary> | ||
| 138 | Bit17 = Bit16 << 1, | ||
| 139 | |||
| 140 | /// <summary>Bit 18 (0x0000000000040000)</summary> | ||
| 141 | Bit18 = Bit17 << 1, | ||
| 142 | |||
| 143 | /// <summary>Bit 19 (0x0000000000080000)</summary> | ||
| 144 | Bit19 = Bit18 << 1, | ||
| 145 | |||
| 146 | /// <summary>Bit 20 (0x0000000000100000)</summary> | ||
| 147 | Bit20 = Bit19 << 1, | ||
| 148 | |||
| 149 | /// <summary>Bit 21 (0x0000000000200000)</summary> | ||
| 150 | Bit21 = Bit20 << 1, | ||
| 151 | |||
| 152 | /// <summary>Bit 22 (0x0000000000400000)</summary> | ||
| 153 | Bit22 = Bit21 << 1, | ||
| 154 | |||
| 155 | /// <summary>Bit 23 (0x0000000000800000)</summary> | ||
| 156 | Bit23 = Bit22 << 1, | ||
| 157 | |||
| 158 | // Byte 3, Bits 24-31 | ||
| 159 | |||
| 160 | /// <summary>Bit 24 (0x0000000001000000)</summary> | ||
| 161 | Bit24 = Bit23 << 1, | ||
| 162 | |||
| 163 | /// <summary>Bit 25 (0x0000000002000000)</summary> | ||
| 164 | Bit25 = Bit24 << 1, | ||
| 165 | |||
| 166 | /// <summary>Bit 26 (0x0000000004000000)</summary> | ||
| 167 | Bit26 = Bit25 << 1, | ||
| 168 | |||
| 169 | /// <summary>Bit 27 (0x0000000008000000)</summary> | ||
| 170 | Bit27 = Bit26 << 1, | ||
| 171 | |||
| 172 | /// <summary>Bit 28 (0x0000000010000000)</summary> | ||
| 173 | Bit28 = Bit27 << 1, | ||
| 174 | |||
| 175 | /// <summary>Bit 29 (0x0000000020000000)</summary> | ||
| 176 | Bit29 = Bit28 << 1, | ||
| 177 | |||
| 178 | /// <summary>Bit 30 (0x0000000040000000)</summary> | ||
| 179 | Bit30 = Bit29 << 1, | ||
| 180 | |||
| 181 | /// <summary>Bit 31 (0x0000000080000000)</summary> | ||
| 182 | Bit31 = Bit30 << 1, | ||
| 183 | |||
| 184 | // Byte 4, Bits 32-39 | ||
| 185 | |||
| 186 | /// <summary>Bit 32 (0x0000000100000000)</summary> | ||
| 187 | Bit32 = Bit31 << 1, | ||
| 188 | |||
| 189 | /// <summary>Bit 33 (0x0000000200000000)</summary> | ||
| 190 | Bit33 = Bit32 << 1, | ||
| 191 | |||
| 192 | /// <summary>Bit 34 (0x0000000400000000)</summary> | ||
| 193 | Bit34 = Bit33 << 1, | ||
| 194 | |||
| 195 | /// <summary>Bit 35 (0x0000000800000000)</summary> | ||
| 196 | Bit35 = Bit34 << 1, | ||
| 197 | |||
| 198 | /// <summary>Bit 36 (0x0000001000000000)</summary> | ||
| 199 | Bit36 = Bit35 << 1, | ||
| 200 | |||
| 201 | /// <summary>Bit 37 (0x0000002000000000)</summary> | ||
| 202 | Bit37 = Bit36 << 1, | ||
| 203 | |||
| 204 | /// <summary>Bit 38 (0x0000004000000000)</summary> | ||
| 205 | Bit38 = Bit37 << 1, | ||
| 206 | |||
| 207 | /// <summary>Bit 39 (0x0000008000000000)</summary> | ||
| 208 | Bit39 = Bit38 << 1, | ||
| 209 | |||
| 210 | // Byte 5, Bits 40-47 | ||
| 211 | |||
| 212 | /// <summary>Bit 40 (0x0000010000000000)</summary> | ||
| 213 | Bit40 = Bit39 << 1, | ||
| 214 | |||
| 215 | /// <summary>Bit 41 (0x0000020000000000)</summary> | ||
| 216 | Bit41 = Bit40 << 1, | ||
| 217 | |||
| 218 | /// <summary>Bit 42 (0x0000040000000000)</summary> | ||
| 219 | Bit42 = Bit41 << 1, | ||
| 220 | |||
| 221 | /// <summary>Bit 43 (0x0000080000000000)</summary> | ||
| 222 | Bit43 = Bit42 << 1, | ||
| 223 | |||
| 224 | /// <summary>Bit 44 (0x0000100000000000)</summary> | ||
| 225 | Bit44 = Bit43 << 1, | ||
| 226 | |||
| 227 | /// <summary>Bit 45 (0x0000200000000000)</summary> | ||
| 228 | Bit45 = Bit44 << 1, | ||
| 229 | |||
| 230 | /// <summary>Bit 46 (0x0000400000000000)</summary> | ||
| 231 | Bit46 = Bit45 << 1, | ||
| 232 | |||
| 233 | /// <summary>Bit 47 (0x0000800000000000)</summary> | ||
| 234 | Bit47 = Bit46 << 1, | ||
| 235 | |||
| 236 | // Byte 6, Bits 48-55 | ||
| 237 | |||
| 238 | /// <summary>Bit 48 (0x0001000000000000)</summary> | ||
| 239 | Bit48 = Bit47 << 1, | ||
| 240 | |||
| 241 | /// <summary>Bit 49 (0x0002000000000000)</summary> | ||
| 242 | Bit49 = Bit48 << 1, | ||
| 243 | |||
| 244 | /// <summary>Bit 50 (0x0004000000000000)</summary> | ||
| 245 | Bit50 = Bit49 << 1, | ||
| 246 | |||
| 247 | /// <summary>Bit 51 (0x0008000000000000)</summary> | ||
| 248 | Bit51 = Bit50 << 1, | ||
| 249 | |||
| 250 | /// <summary>Bit 52 (0x0010000000000000)</summary> | ||
| 251 | Bit52 = Bit51 << 1, | ||
| 252 | |||
| 253 | /// <summary>Bit 53 (0x0020000000000000)</summary> | ||
| 254 | Bit53 = Bit52 << 1, | ||
| 255 | |||
| 256 | /// <summary>Bit 54 (0x0040000000000000)</summary> | ||
| 257 | Bit54 = Bit53 << 1, | ||
| 258 | |||
| 259 | /// <summary>Bit 55 (0x0080000000000000)</summary> | ||
| 260 | Bit55 = Bit54 << 1, | ||
| 261 | |||
| 262 | // Byte 7, Bits 56-63 | ||
| 263 | |||
| 264 | /// <summary>Bit 56 (0x0100000000000000)</summary> | ||
| 265 | Bit56 = Bit55 << 1, | ||
| 266 | |||
| 267 | /// <summary>Bit 57 (0x0200000000000000)</summary> | ||
| 268 | Bit57 = Bit56 << 1, | ||
| 269 | |||
| 270 | /// <summary>Bit 58 (0x0400000000000000)</summary> | ||
| 271 | Bit58 = Bit57 << 1, | ||
| 272 | |||
| 273 | /// <summary>Bit 59 (0x0800000000000000)</summary> | ||
| 274 | Bit59 = Bit58 << 1, | ||
| 275 | |||
| 276 | /// <summary>Bit 60 (0x1000000000000000)</summary> | ||
| 277 | Bit60 = Bit59 << 1, | ||
| 278 | |||
| 279 | /// <summary>Bit 61 (0x2000000000000000)</summary> | ||
| 280 | Bit61 = Bit60 << 1, | ||
| 281 | |||
| 282 | /// <summary>Bit 62 (0x4000000000000000)</summary> | ||
| 283 | Bit62 = Bit61 << 1, | ||
| 284 | |||
| 285 | /// <summary>Bit 63 (0x8000000000000000)</summary> | ||
| 286 | Bit63 = Bit62 << 1 | ||
| 287 | } | ||
| 288 | |||
| 289 | #endregion | ||
| 290 | |||
| 291 | /// <summary> | ||
| 292 | /// Defines extension methods related to bit operations. | ||
| 293 | /// </summary> | ||
| 294 | public static class BitExtensions | ||
| 295 | { | ||
| 296 | /// <summary> | ||
| 297 | /// Gets the bit value for the specified bit index (0 - 63). | ||
| 298 | /// </summary> | ||
| 299 | /// <param name="bit">Bit index (0 - 63)</param> | ||
| 300 | /// <returns>Value of the specified <paramref name="bit"/>.</returns> | ||
| 301 | /// <exception cref="ArgumentOutOfRangeException">Parameter must be between 0 and 63.</exception> | ||
| 302 | [CLSCompliant(false)] | ||
| 303 | public static Bits BitVal(int bit) | ||
| 304 | { | ||
| 305 | switch (bit) | ||
| 306 | { | ||
| 307 | #region [ Bit Cases (0 - 63) ] | ||
| 308 | |||
| 309 | case 00: return Bits.Bit00; | ||
| 310 | case 01: return Bits.Bit01; | ||
| 311 | case 02: return Bits.Bit02; | ||
| 312 | case 03: return Bits.Bit03; | ||
| 313 | case 04: return Bits.Bit04; | ||
| 314 | case 05: return Bits.Bit05; | ||
| 315 | case 06: return Bits.Bit06; | ||
| 316 | case 07: return Bits.Bit07; | ||
| 317 | case 08: return Bits.Bit08; | ||
| 318 | case 09: return Bits.Bit09; | ||
| 319 | case 10: return Bits.Bit10; | ||
| 320 | case 11: return Bits.Bit11; | ||
| 321 | case 12: return Bits.Bit12; | ||
| 322 | case 13: return Bits.Bit13; | ||
| 323 | case 14: return Bits.Bit14; | ||
| 324 | case 15: return Bits.Bit15; | ||
| 325 | case 16: return Bits.Bit16; | ||
| 326 | case 17: return Bits.Bit17; | ||
| 327 | case 18: return Bits.Bit18; | ||
| 328 | case 19: return Bits.Bit19; | ||
| 329 | case 20: return Bits.Bit20; | ||
| 330 | case 21: return Bits.Bit21; | ||
| 331 | case 22: return Bits.Bit22; | ||
| 332 | case 23: return Bits.Bit23; | ||
| 333 | case 24: return Bits.Bit24; | ||
| 334 | case 25: return Bits.Bit25; | ||
| 335 | case 26: return Bits.Bit26; | ||
| 336 | case 27: return Bits.Bit27; | ||
| 337 | case 28: return Bits.Bit28; | ||
| 338 | case 29: return Bits.Bit29; | ||
| 339 | case 30: return Bits.Bit30; | ||
| 340 | case 31: return Bits.Bit31; | ||
| 341 | case 32: return Bits.Bit32; | ||
| 342 | case 33: return Bits.Bit33; | ||
| 343 | case 34: return Bits.Bit34; | ||
| 344 | case 35: return Bits.Bit35; | ||
| 345 | case 36: return Bits.Bit36; | ||
| 346 | case 37: return Bits.Bit37; | ||
| 347 | case 38: return Bits.Bit38; | ||
| 348 | case 39: return Bits.Bit39; | ||
| 349 | case 40: return Bits.Bit40; | ||
| 350 | case 41: return Bits.Bit41; | ||
| 351 | case 42: return Bits.Bit42; | ||
| 352 | case 43: return Bits.Bit43; | ||
| 353 | case 44: return Bits.Bit44; | ||
| 354 | case 45: return Bits.Bit45; | ||
| 355 | case 46: return Bits.Bit46; | ||
| 356 | case 47: return Bits.Bit47; | ||
| 357 | case 48: return Bits.Bit48; | ||
| 358 | case 49: return Bits.Bit49; | ||
| 359 | case 50: return Bits.Bit50; | ||
| 360 | case 51: return Bits.Bit51; | ||
| 361 | case 52: return Bits.Bit52; | ||
| 362 | case 53: return Bits.Bit53; | ||
| 363 | case 54: return Bits.Bit54; | ||
| 364 | case 55: return Bits.Bit55; | ||
| 365 | case 56: return Bits.Bit56; | ||
| 366 | case 57: return Bits.Bit57; | ||
| 367 | case 58: return Bits.Bit58; | ||
| 368 | case 59: return Bits.Bit59; | ||
| 369 | case 60: return Bits.Bit60; | ||
| 370 | case 61: return Bits.Bit61; | ||
| 371 | case 62: return Bits.Bit62; | ||
| 372 | case 63: return Bits.Bit63; | ||
| 373 | |||
| 374 | #endregion | ||
| 375 | |||
| 376 | default: | ||
| 377 | throw new ArgumentOutOfRangeException("bit", "Parameter must be between 0 and 63"); | ||
| 378 | } | ||
| 379 | } | ||
| 380 | |||
| 381 | #region [ SetBits Extensions ] | ||
| 382 | |||
| 383 | /// <summary> | ||
| 384 | /// Returns value with specified <paramref name="bits"/> set. | ||
| 385 | /// </summary> | ||
| 386 | /// <param name="source">Value source.</param> | ||
| 387 | /// <param name="bits"><see cref="Bits"/> to set.</param> | ||
| 388 | /// <returns><see cref="sbyte"/> value with specified <paramref name="bits"/> set.</returns> | ||
| 389 | [CLSCompliant(false)] | ||
| 390 | public static sbyte SetBits(this sbyte source, Bits bits) | ||
| 391 | { | ||
| 392 | checked | ||
| 393 | { | ||
| 394 | return SetBits(source, (sbyte)bits); | ||
| 395 | } | ||
| 396 | } | ||
| 397 | |||
| 398 | /// <summary> | ||
| 399 | /// Returns value with specified <paramref name="bits"/> set. | ||
| 400 | /// </summary> | ||
| 401 | /// <param name="source">Value source.</param> | ||
| 402 | /// <param name="bits">Bit-mask of the bits to set.</param> | ||
| 403 | /// <returns><see cref="sbyte"/> value with specified <paramref name="bits"/> set.</returns> | ||
| 404 | [CLSCompliant(false)] | ||
| 405 | public static sbyte SetBits(this sbyte source, sbyte bits) | ||
| 406 | { | ||
| 407 | return ((sbyte)(source | bits)); | ||
| 408 | } | ||
| 409 | |||
| 410 | /// <summary> | ||
| 411 | /// Returns value with specified <paramref name="bits"/> set. | ||
| 412 | /// </summary> | ||
| 413 | /// <param name="source">Value source.</param> | ||
| 414 | /// <param name="bits"><see cref="Bits"/> to set.</param> | ||
| 415 | /// <returns><see cref="byte"/> value with specified <paramref name="bits"/> set.</returns> | ||
| 416 | [CLSCompliant(false)] | ||
| 417 | public static byte SetBits(this byte source, Bits bits) | ||
| 418 | { | ||
| 419 | checked | ||
| 420 | { | ||
| 421 | return SetBits(source, (byte)bits); | ||
| 422 | } | ||
| 423 | } | ||
| 424 | |||
| 425 | /// <summary> | ||
| 426 | /// Returns value with specified <paramref name="bits"/> set. | ||
| 427 | /// </summary> | ||
| 428 | /// <param name="source">Value source.</param> | ||
| 429 | /// <param name="bits">Bit-mask of the bits to set.</param> | ||
| 430 | /// <returns><see cref="byte"/> value with specified <paramref name="bits"/> set.</returns> | ||
| 431 | public static byte SetBits(this byte source, byte bits) | ||
| 432 | { | ||
| 433 | return ((byte)(source | bits)); | ||
| 434 | } | ||
| 435 | |||
| 436 | /// <summary> | ||
| 437 | /// Returns value with specified <paramref name="bits"/> set. | ||
| 438 | /// </summary> | ||
| 439 | /// <param name="source">Value source.</param> | ||
| 440 | /// <param name="bits"><see cref="Bits"/> to set.</param> | ||
| 441 | /// <returns><see cref="short"/> value with specified <paramref name="bits"/> set.</returns> | ||
| 442 | [CLSCompliant(false)] | ||
| 443 | public static short SetBits(this short source, Bits bits) | ||
| 444 | { | ||
| 445 | checked | ||
| 446 | { | ||
| 447 | return SetBits(source, (short)bits); | ||
| 448 | } | ||
| 449 | } | ||
| 450 | |||
| 451 | /// <summary> | ||
| 452 | /// Returns value with specified <paramref name="bits"/> set. | ||
| 453 | /// </summary> | ||
| 454 | /// <param name="source">Value source.</param> | ||
| 455 | /// <param name="bits">Bit-mask of the bits to set.</param> | ||
| 456 | /// <returns><see cref="short"/> value with specified <paramref name="bits"/> set.</returns> | ||
| 457 | public static short SetBits(this short source, short bits) | ||
| 458 | { | ||
| 459 | return ((short)(source | bits)); | ||
| 460 | } | ||
| 461 | |||
| 462 | /// <summary> | ||
| 463 | /// Returns value with specified <paramref name="bits"/> set. | ||
| 464 | /// </summary> | ||
| 465 | /// <param name="source">Value source.</param> | ||
| 466 | /// <param name="bits"><see cref="Bits"/> to set.</param> | ||
| 467 | /// <returns><see cref="ushort"/> value with specified <paramref name="bits"/> set.</returns> | ||
| 468 | [CLSCompliant(false)] | ||
| 469 | public static ushort SetBits(this ushort source, Bits bits) | ||
| 470 | { | ||
| 471 | checked | ||
| 472 | { | ||
| 473 | return SetBits(source, (ushort)bits); | ||
| 474 | } | ||
| 475 | } | ||
| 476 | |||
| 477 | /// <summary> | ||
| 478 | /// Returns value with specified <paramref name="bits"/> set. | ||
| 479 | /// </summary> | ||
| 480 | /// <param name="source">Value source.</param> | ||
| 481 | /// <param name="bits">Bit-mask of the bits to set.</param> | ||
| 482 | /// <returns><see cref="ushort"/> value with specified <paramref name="bits"/> set.</returns> | ||
| 483 | [CLSCompliant(false)] | ||
| 484 | public static ushort SetBits(this ushort source, ushort bits) | ||
| 485 | { | ||
| 486 | return ((ushort)(source | bits)); | ||
| 487 | } | ||
| 488 | |||
| 489 | /// <summary> | ||
| 490 | /// Returns value with specified <paramref name="bits"/> set. | ||
| 491 | /// </summary> | ||
| 492 | /// <param name="source">Value source.</param> | ||
| 493 | /// <param name="bits"><see cref="Bits"/> to set.</param> | ||
| 494 | /// <returns><see cref="Int24"/> value with specified <paramref name="bits"/> set.</returns> | ||
| 495 | [CLSCompliant(false)] | ||
| 496 | public static Int24 SetBits(this Int24 source, Bits bits) | ||
| 497 | { | ||
| 498 | checked | ||
| 499 | { | ||
| 500 | return SetBits(source, (Int24)bits); | ||
| 501 | } | ||
| 502 | } | ||
| 503 | |||
| 504 | /// <summary> | ||
| 505 | /// Returns value with specified <paramref name="bits"/> set. | ||
| 506 | /// </summary> | ||
| 507 | /// <param name="source">Value source.</param> | ||
| 508 | /// <param name="bits">Bit-mask of the bits to set.</param> | ||
| 509 | /// <returns><see cref="Int24"/> value with specified <paramref name="bits"/> set.</returns> | ||
| 510 | public static Int24 SetBits(this Int24 source, Int24 bits) | ||
| 511 | { | ||
| 512 | return (source | bits); | ||
| 513 | } | ||
| 514 | |||
| 515 | /// <summary> | ||
| 516 | /// Returns value with specified <paramref name="bits"/> set. | ||
| 517 | /// </summary> | ||
| 518 | /// <param name="source">Value source.</param> | ||
| 519 | /// <param name="bits"><see cref="Bits"/> to set.</param> | ||
| 520 | /// <returns><see cref="UInt24"/> value with specified <paramref name="bits"/> set.</returns> | ||
| 521 | [CLSCompliant(false)] | ||
| 522 | public static UInt24 SetBits(this UInt24 source, Bits bits) | ||
| 523 | { | ||
| 524 | checked | ||
| 525 | { | ||
| 526 | return SetBits(source, (UInt24)bits); | ||
| 527 | } | ||
| 528 | } | ||
| 529 | |||
| 530 | /// <summary> | ||
| 531 | /// Returns value with specified <paramref name="bits"/> set. | ||
| 532 | /// </summary> | ||
| 533 | /// <param name="source">Value source.</param> | ||
| 534 | /// <param name="bits">Bit-mask of the bits to set.</param> | ||
| 535 | /// <returns><see cref="UInt24"/> value with specified <paramref name="bits"/> set.</returns> | ||
| 536 | [CLSCompliant(false)] | ||
| 537 | public static UInt24 SetBits(this UInt24 source, UInt24 bits) | ||
| 538 | { | ||
| 539 | return (source | bits); | ||
| 540 | } | ||
| 541 | |||
| 542 | /// <summary> | ||
| 543 | /// Returns value with specified <paramref name="bits"/> set. | ||
| 544 | /// </summary> | ||
| 545 | /// <param name="source">Value source.</param> | ||
| 546 | /// <param name="bits"><see cref="Bits"/> to set.</param> | ||
| 547 | /// <returns><see cref="int"/> value with specified <paramref name="bits"/> set.</returns> | ||
| 548 | [CLSCompliant(false)] | ||
| 549 | public static int SetBits(this int source, Bits bits) | ||
| 550 | { | ||
| 551 | checked | ||
| 552 | { | ||
| 553 | return SetBits(source, (int)bits); | ||
| 554 | } | ||
| 555 | } | ||
| 556 | |||
| 557 | /// <summary> | ||
| 558 | /// Returns value with specified <paramref name="bits"/> set. | ||
| 559 | /// </summary> | ||
| 560 | /// <param name="source">Value source.</param> | ||
| 561 | /// <param name="bits">Bit-mask of the bits to set.</param> | ||
| 562 | /// <returns><see cref="int"/> value with specified <paramref name="bits"/> set.</returns> | ||
| 563 | public static int SetBits(this int source, int bits) | ||
| 564 | { | ||
| 565 | return (source | bits); | ||
| 566 | } | ||
| 567 | |||
| 568 | /// <summary> | ||
| 569 | /// Returns value with specified <paramref name="bits"/> set. | ||
| 570 | /// </summary> | ||
| 571 | /// <param name="source">Value source.</param> | ||
| 572 | /// <param name="bits"><see cref="Bits"/> to set.</param> | ||
| 573 | /// <returns><see cref="uint"/> value with specified <paramref name="bits"/> set.</returns> | ||
| 574 | [CLSCompliant(false)] | ||
| 575 | public static uint SetBits(this uint source, Bits bits) | ||
| 576 | { | ||
| 577 | checked | ||
| 578 | { | ||
| 579 | return SetBits(source, (uint)bits); | ||
| 580 | } | ||
| 581 | } | ||
| 582 | |||
| 583 | /// <summary> | ||
| 584 | /// Returns value with specified <paramref name="bits"/> set. | ||
| 585 | /// </summary> | ||
| 586 | /// <param name="source">Value source.</param> | ||
| 587 | /// <param name="bits">Bit-mask of the bits to set.</param> | ||
| 588 | /// <returns><see cref="uint"/> value with specified <paramref name="bits"/> set.</returns> | ||
| 589 | [CLSCompliant(false)] | ||
| 590 | public static uint SetBits(this uint source, uint bits) | ||
| 591 | { | ||
| 592 | return (source | bits); | ||
| 593 | } | ||
| 594 | |||
| 595 | /// <summary> | ||
| 596 | /// Returns value with specified <paramref name="bits"/> set. | ||
| 597 | /// </summary> | ||
| 598 | /// <param name="source">Value source.</param> | ||
| 599 | /// <param name="bits"><see cref="Bits"/> to set.</param> | ||
| 600 | /// <returns><see cref="long"/> value with specified <paramref name="bits"/> set.</returns> | ||
| 601 | [CLSCompliant(false)] | ||
| 602 | public static long SetBits(this long source, Bits bits) | ||
| 603 | { | ||
| 604 | checked | ||
| 605 | { | ||
| 606 | return SetBits(source, (long)bits); | ||
| 607 | } | ||
| 608 | } | ||
| 609 | |||
| 610 | /// <summary> | ||
| 611 | /// Returns value with specified <paramref name="bits"/> set. | ||
| 612 | /// </summary> | ||
| 613 | /// <param name="source">Value source.</param> | ||
| 614 | /// <param name="bits">Bit-mask of the bits to set.</param> | ||
| 615 | /// <returns><see cref="long"/> value with specified <paramref name="bits"/> set.</returns> | ||
| 616 | public static long SetBits(this long source, long bits) | ||
| 617 | { | ||
| 618 | return (source | bits); | ||
| 619 | } | ||
| 620 | |||
| 621 | /// <summary> | ||
| 622 | /// Returns value with specified <paramref name="bits"/> set. | ||
| 623 | /// </summary> | ||
| 624 | /// <param name="source">Value source.</param> | ||
| 625 | /// <param name="bits"><see cref="Bits"/> to set.</param> | ||
| 626 | /// <returns><see cref="ulong"/> value with specified <paramref name="bits"/> set.</returns> | ||
| 627 | [CLSCompliant(false)] | ||
| 628 | public static ulong SetBits(this ulong source, Bits bits) | ||
| 629 | { | ||
| 630 | checked | ||
| 631 | { | ||
| 632 | return SetBits(source, (ulong)bits); | ||
| 633 | } | ||
| 634 | } | ||
| 635 | |||
| 636 | /// <summary> | ||
| 637 | /// Returns value with specified <paramref name="bits"/> set. | ||
| 638 | /// </summary> | ||
| 639 | /// <param name="source">Value source.</param> | ||
| 640 | /// <param name="bits">Bit-mask of the bits to set.</param> | ||
| 641 | /// <returns><see cref="ulong"/> value with specified <paramref name="bits"/> set.</returns> | ||
| 642 | [CLSCompliant(false)] | ||
| 643 | public static ulong SetBits(this ulong source, ulong bits) | ||
| 644 | { | ||
| 645 | return (source | bits); | ||
| 646 | } | ||
| 647 | |||
| 648 | #endregion | ||
| 649 | |||
| 650 | #region [ ClearBits Extensions ] | ||
| 651 | |||
| 652 | /// <summary> | ||
| 653 | /// Returns value with specified <paramref name="bits"/> cleared. | ||
| 654 | /// </summary> | ||
| 655 | /// <param name="source">Value source.</param> | ||
| 656 | /// <param name="bits"><see cref="Bits"/> to clear.</param> | ||
| 657 | /// <returns><see cref="sbyte"/> value with specified <paramref name="bits"/> cleared.</returns> | ||
| 658 | [CLSCompliant(false)] | ||
| 659 | public static sbyte ClearBits(this sbyte source, Bits bits) | ||
| 660 | { | ||
| 661 | checked | ||
| 662 | { | ||
| 663 | return ClearBits(source, (sbyte)bits); | ||
| 664 | } | ||
| 665 | } | ||
| 666 | |||
| 667 | /// <summary> | ||
| 668 | /// Returns value with specified <paramref name="bits"/> cleared. | ||
| 669 | /// </summary> | ||
| 670 | /// <param name="source">Value source.</param> | ||
| 671 | /// <param name="bits">Bit-mask of the bits to clear.</param> | ||
| 672 | /// <returns><see cref="sbyte"/> value with specified <paramref name="bits"/> cleared.</returns> | ||
| 673 | [CLSCompliant(false)] | ||
| 674 | public static sbyte ClearBits(this sbyte source, sbyte bits) | ||
| 675 | { | ||
| 676 | return ((sbyte)(source & ~bits)); | ||
| 677 | } | ||
| 678 | |||
| 679 | /// <summary> | ||
| 680 | /// Returns value with specified <paramref name="bits"/> cleared. | ||
| 681 | /// </summary> | ||
| 682 | /// <param name="source">Value source.</param> | ||
| 683 | /// <param name="bits"><see cref="Bits"/> to clear.</param> | ||
| 684 | /// <returns><see cref="byte"/> value with specified <paramref name="bits"/> cleared.</returns> | ||
| 685 | [CLSCompliant(false)] | ||
| 686 | public static byte ClearBits(this byte source, Bits bits) | ||
| 687 | { | ||
| 688 | checked | ||
| 689 | { | ||
| 690 | return ClearBits(source, (byte)bits); | ||
| 691 | } | ||
| 692 | } | ||
| 693 | |||
| 694 | /// <summary> | ||
| 695 | /// Returns value with specified <paramref name="bits"/> cleared. | ||
| 696 | /// </summary> | ||
| 697 | /// <param name="source">Value source.</param> | ||
| 698 | /// <param name="bits">Bit-mask of the bits to clear.</param> | ||
| 699 | /// <returns><see cref="byte"/> value with specified <paramref name="bits"/> cleared.</returns> | ||
| 700 | public static byte ClearBits(this byte source, byte bits) | ||
| 701 | { | ||
| 702 | return ((byte)(source & ~bits)); | ||
| 703 | } | ||
| 704 | |||
| 705 | /// <summary> | ||
| 706 | /// Returns value with specified <paramref name="bits"/> cleared. | ||
| 707 | /// </summary> | ||
| 708 | /// <param name="source">Value source.</param> | ||
| 709 | /// <param name="bits"><see cref="Bits"/> to clear.</param> | ||
| 710 | /// <returns><see cref="short"/> value with specified <paramref name="bits"/> cleared.</returns> | ||
| 711 | [CLSCompliant(false)] | ||
| 712 | public static short ClearBits(this short source, Bits bits) | ||
| 713 | { | ||
| 714 | checked | ||
| 715 | { | ||
| 716 | return ClearBits(source, (short)bits); | ||
| 717 | } | ||
| 718 | } | ||
| 719 | |||
| 720 | /// <summary> | ||
| 721 | /// Returns value with specified <paramref name="bits"/> cleared. | ||
| 722 | /// </summary> | ||
| 723 | /// <param name="source">Value source.</param> | ||
| 724 | /// <param name="bits">Bit-mask of the bits to clear.</param> | ||
| 725 | /// <returns><see cref="short"/> value with specified <paramref name="bits"/> cleared.</returns> | ||
| 726 | public static short ClearBits(this short source, short bits) | ||
| 727 | { | ||
| 728 | return ((short)(source & ~bits)); | ||
| 729 | } | ||
| 730 | |||
| 731 | /// <summary> | ||
| 732 | /// Returns value with specified <paramref name="bits"/> cleared. | ||
| 733 | /// </summary> | ||
| 734 | /// <param name="source">Value source.</param> | ||
| 735 | /// <param name="bits"><see cref="Bits"/> to clear.</param> | ||
| 736 | /// <returns><see cref="ushort"/> value with specified <paramref name="bits"/> cleared.</returns> | ||
| 737 | [CLSCompliant(false)] | ||
| 738 | public static ushort ClearBits(this ushort source, Bits bits) | ||
| 739 | { | ||
| 740 | checked | ||
| 741 | { | ||
| 742 | return ClearBits(source, (ushort)bits); | ||
| 743 | } | ||
| 744 | } | ||
| 745 | |||
| 746 | /// <summary> | ||
| 747 | /// Returns value with specified <paramref name="bits"/> cleared. | ||
| 748 | /// </summary> | ||
| 749 | /// <param name="source">Value source.</param> | ||
| 750 | /// <param name="bits">Bit-mask of the bits to clear.</param> | ||
| 751 | /// <returns><see cref="ushort"/> value with specified <paramref name="bits"/> cleared.</returns> | ||
| 752 | [CLSCompliant(false)] | ||
| 753 | public static ushort ClearBits(this ushort source, ushort bits) | ||
| 754 | { | ||
| 755 | return ((ushort)(source & ~bits)); | ||
| 756 | } | ||
| 757 | |||
| 758 | /// <summary> | ||
| 759 | /// Returns value with specified <paramref name="bits"/> cleared. | ||
| 760 | /// </summary> | ||
| 761 | /// <param name="source">Value source.</param> | ||
| 762 | /// <param name="bits"><see cref="Bits"/> to clear.</param> | ||
| 763 | /// <returns><see cref="Int24"/> value with specified <paramref name="bits"/> cleared.</returns> | ||
| 764 | [CLSCompliant(false)] | ||
| 765 | public static Int24 ClearBits(this Int24 source, Bits bits) | ||
| 766 | { | ||
| 767 | checked | ||
| 768 | { | ||
| 769 | return ClearBits(source, (Int24)bits); | ||
| 770 | } | ||
| 771 | } | ||
| 772 | |||
| 773 | /// <summary> | ||
| 774 | /// Returns value with specified <paramref name="bits"/> cleared. | ||
| 775 | /// </summary> | ||
| 776 | /// <param name="source">Value source.</param> | ||
| 777 | /// <param name="bits">Bit-mask of the bits to clear.</param> | ||
| 778 | /// <returns><see cref="Int24"/> value with specified <paramref name="bits"/> cleared.</returns> | ||
| 779 | public static Int24 ClearBits(this Int24 source, Int24 bits) | ||
| 780 | { | ||
| 781 | return (source & ~bits); | ||
| 782 | } | ||
| 783 | |||
| 784 | /// <summary> | ||
| 785 | /// Returns value with specified <paramref name="bits"/> cleared. | ||
| 786 | /// </summary> | ||
| 787 | /// <param name="source">Value source.</param> | ||
| 788 | /// <param name="bits"><see cref="Bits"/> to clear.</param> | ||
| 789 | /// <returns><see cref="UInt24"/> value with specified <paramref name="bits"/> cleared.</returns> | ||
| 790 | [CLSCompliant(false)] | ||
| 791 | public static UInt24 ClearBits(this UInt24 source, Bits bits) | ||
| 792 | { | ||
| 793 | checked | ||
| 794 | { | ||
| 795 | return ClearBits(source, (UInt24)bits); | ||
| 796 | } | ||
| 797 | } | ||
| 798 | |||
| 799 | /// <summary> | ||
| 800 | /// Returns value with specified <paramref name="bits"/> cleared. | ||
| 801 | /// </summary> | ||
| 802 | /// <param name="source">Value source.</param> | ||
| 803 | /// <param name="bits">Bit-mask of the bits to clear.</param> | ||
| 804 | /// <returns><see cref="UInt24"/> value with specified <paramref name="bits"/> cleared.</returns> | ||
| 805 | [CLSCompliant(false)] | ||
| 806 | public static UInt24 ClearBits(this UInt24 source, UInt24 bits) | ||
| 807 | { | ||
| 808 | return (source & ~bits); | ||
| 809 | } | ||
| 810 | |||
| 811 | /// <summary> | ||
| 812 | /// Returns value with specified <paramref name="bits"/> cleared. | ||
| 813 | /// </summary> | ||
| 814 | /// <param name="source">Value source.</param> | ||
| 815 | /// <param name="bits"><see cref="Bits"/> to clear.</param> | ||
| 816 | /// <returns><see cref="int"/> value with specified <paramref name="bits"/> cleared.</returns> | ||
| 817 | [CLSCompliant(false)] | ||
| 818 | public static int ClearBits(this int source, Bits bits) | ||
| 819 | { | ||
| 820 | checked | ||
| 821 | { | ||
| 822 | return ClearBits(source, (int)bits); | ||
| 823 | } | ||
| 824 | } | ||
| 825 | |||
| 826 | /// <summary> | ||
| 827 | /// Returns value with specified <paramref name="bits"/> cleared. | ||
| 828 | /// </summary> | ||
| 829 | /// <param name="source">Value source.</param> | ||
| 830 | /// <param name="bits">Bit-mask of the bits to clear.</param> | ||
| 831 | /// <returns><see cref="int"/> value with specified <paramref name="bits"/> cleared.</returns> | ||
| 832 | public static int ClearBits(this int source, int bits) | ||
| 833 | { | ||
| 834 | return (source & ~bits); | ||
| 835 | } | ||
| 836 | |||
| 837 | /// <summary> | ||
| 838 | /// Returns value with specified <paramref name="bits"/> cleared. | ||
| 839 | /// </summary> | ||
| 840 | /// <param name="source">Value source.</param> | ||
| 841 | /// <param name="bits"><see cref="Bits"/> to clear.</param> | ||
| 842 | /// <returns><see cref="uint"/> value with specified <paramref name="bits"/> cleared.</returns> | ||
| 843 | [CLSCompliant(false)] | ||
| 844 | public static uint ClearBits(this uint source, Bits bits) | ||
| 845 | { | ||
| 846 | checked | ||
| 847 | { | ||
| 848 | return ClearBits(source, (uint)bits); | ||
| 849 | } | ||
| 850 | } | ||
| 851 | |||
| 852 | /// <summary> | ||
| 853 | /// Returns value with specified <paramref name="bits"/> cleared. | ||
| 854 | /// </summary> | ||
| 855 | /// <param name="source">Value source.</param> | ||
| 856 | /// <param name="bits">Bit-mask of the bits to clear.</param> | ||
| 857 | /// <returns><see cref="uint"/> value with specified <paramref name="bits"/> cleared.</returns> | ||
| 858 | [CLSCompliant(false)] | ||
| 859 | public static uint ClearBits(this uint source, uint bits) | ||
| 860 | { | ||
| 861 | return (source & ~bits); | ||
| 862 | } | ||
| 863 | |||
| 864 | /// <summary> | ||
| 865 | /// Returns value with specified <paramref name="bits"/> cleared. | ||
| 866 | /// </summary> | ||
| 867 | /// <param name="source">Value source.</param> | ||
| 868 | /// <param name="bits"><see cref="Bits"/> to clear.</param> | ||
| 869 | /// <returns><see cref="long"/> value with specified <paramref name="bits"/> cleared.</returns> | ||
| 870 | [CLSCompliant(false)] | ||
| 871 | public static long ClearBits(this long source, Bits bits) | ||
| 872 | { | ||
| 873 | checked | ||
| 874 | { | ||
| 875 | return ClearBits(source, (long)bits); | ||
| 876 | } | ||
| 877 | } | ||
| 878 | |||
| 879 | /// <summary> | ||
| 880 | /// Returns value with specified <paramref name="bits"/> cleared. | ||
| 881 | /// </summary> | ||
| 882 | /// <param name="source">Value source.</param> | ||
| 883 | /// <param name="bits">Bit-mask of the bits to clear.</param> | ||
| 884 | /// <returns><see cref="long"/> value with specified <paramref name="bits"/> cleared.</returns> | ||
| 885 | public static long ClearBits(this long source, long bits) | ||
| 886 | { | ||
| 887 | return (source & ~bits); | ||
| 888 | } | ||
| 889 | |||
| 890 | /// <summary> | ||
| 891 | /// Returns value with specified <paramref name="bits"/> cleared. | ||
| 892 | /// </summary> | ||
| 893 | /// <param name="source">Value source.</param> | ||
| 894 | /// <param name="bits"><see cref="Bits"/> to clear.</param> | ||
| 895 | /// <returns><see cref="ulong"/> value with specified <paramref name="bits"/> cleared.</returns> | ||
| 896 | [CLSCompliant(false)] | ||
| 897 | public static ulong ClearBits(this ulong source, Bits bits) | ||
| 898 | { | ||
| 899 | checked | ||
| 900 | { | ||
| 901 | return ClearBits(source, (ulong)bits); | ||
| 902 | } | ||
| 903 | } | ||
| 904 | |||
| 905 | /// <summary> | ||
| 906 | /// Returns value with specified <paramref name="bits"/> cleared. | ||
| 907 | /// </summary> | ||
| 908 | /// <param name="source">Value source.</param> | ||
| 909 | /// <param name="bits">Bit-mask of the bits to clear.</param> | ||
| 910 | /// <returns><see cref="ulong"/> value with specified <paramref name="bits"/> cleared.</returns> | ||
| 911 | [CLSCompliant(false)] | ||
| 912 | public static ulong ClearBits(this ulong source, ulong bits) | ||
| 913 | { | ||
| 914 | return (source & ~bits); | ||
| 915 | } | ||
| 916 | |||
| 917 | #endregion | ||
| 918 | |||
| 919 | #region [ CheckBits Extensions ] | ||
| 920 | |||
| 921 | /// <summary> | ||
| 922 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 923 | /// </summary> | ||
| 924 | /// <param name="source">Value source.</param> | ||
| 925 | /// <param name="bits"><see cref="Bits"/> to check.</param> | ||
| 926 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 927 | [CLSCompliant(false)] | ||
| 928 | public static bool CheckBits(this sbyte source, Bits bits) | ||
| 929 | { | ||
| 930 | checked | ||
| 931 | { | ||
| 932 | return CheckBits(source, (sbyte)bits); | ||
| 933 | } | ||
| 934 | } | ||
| 935 | |||
| 936 | /// <summary> | ||
| 937 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 938 | /// </summary> | ||
| 939 | /// <param name="source">Value source.</param> | ||
| 940 | /// <param name="bits">Bit-mask of the bits to check.</param> | ||
| 941 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 942 | [CLSCompliant(false)] | ||
| 943 | public static bool CheckBits(this sbyte source, sbyte bits) | ||
| 944 | { | ||
| 945 | return CheckBits(source, bits, true); | ||
| 946 | } | ||
| 947 | |||
| 948 | /// <summary> | ||
| 949 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 950 | /// </summary> | ||
| 951 | /// <param name="source">Value source.</param> | ||
| 952 | /// <param name="bits"><see cref="Bits"/> to check.</param> | ||
| 953 | /// <param name="allBits">true to check if all <paramref name="bits"/> are set; otherwise false.</param> | ||
| 954 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 955 | [CLSCompliant(false)] | ||
| 956 | public static bool CheckBits(this sbyte source, Bits bits, bool allBits) | ||
| 957 | { | ||
| 958 | checked | ||
| 959 | { | ||
| 960 | return CheckBits(source, (sbyte)bits, allBits); | ||
| 961 | } | ||
| 962 | } | ||
| 963 | |||
| 964 | /// <summary> | ||
| 965 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 966 | /// </summary> | ||
| 967 | /// <param name="source">Value source.</param> | ||
| 968 | /// <param name="bits">Bit-mask of the bits to check.</param> | ||
| 969 | /// <param name="allBits">true to check if all <paramref name="bits"/> are set; otherwise false.</param> | ||
| 970 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 971 | [CLSCompliant(false)] | ||
| 972 | public static bool CheckBits(this sbyte source, sbyte bits, bool allBits) | ||
| 973 | { | ||
| 974 | return (allBits ? ((source & bits) == bits) : ((source & bits) != 0)); | ||
| 975 | } | ||
| 976 | |||
| 977 | /// <summary> | ||
| 978 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 979 | /// </summary> | ||
| 980 | /// <param name="source">Value source.</param> | ||
| 981 | /// <param name="bits"><see cref="Bits"/> to check.</param> | ||
| 982 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 983 | [CLSCompliant(false)] | ||
| 984 | public static bool CheckBits(this byte source, Bits bits) | ||
| 985 | { | ||
| 986 | checked | ||
| 987 | { | ||
| 988 | return CheckBits(source, (byte)bits); | ||
| 989 | } | ||
| 990 | } | ||
| 991 | |||
| 992 | /// <summary> | ||
| 993 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 994 | /// </summary> | ||
| 995 | /// <param name="source">Value source.</param> | ||
| 996 | /// <param name="bits">Bit-mask of the bits to check.</param> | ||
| 997 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 998 | public static bool CheckBits(this byte source, byte bits) | ||
| 999 | { | ||
| 1000 | return CheckBits(source, bits, true); | ||
| 1001 | } | ||
| 1002 | |||
| 1003 | /// <summary> | ||
| 1004 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1005 | /// </summary> | ||
| 1006 | /// <param name="source">Value source.</param> | ||
| 1007 | /// <param name="bits"><see cref="Bits"/> to check.</param> | ||
| 1008 | /// <param name="allBits">true to check if all <paramref name="bits"/> are set; otherwise false.</param> | ||
| 1009 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1010 | [CLSCompliant(false)] | ||
| 1011 | public static bool CheckBits(this byte source, Bits bits, bool allBits) | ||
| 1012 | { | ||
| 1013 | checked | ||
| 1014 | { | ||
| 1015 | return CheckBits(source, (byte)bits, allBits); | ||
| 1016 | } | ||
| 1017 | } | ||
| 1018 | |||
| 1019 | /// <summary> | ||
| 1020 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1021 | /// </summary> | ||
| 1022 | /// <param name="source">Value source.</param> | ||
| 1023 | /// <param name="bits">Bit-mask of the bits to check.</param> | ||
| 1024 | /// <param name="allBits">true to check if all <paramref name="bits"/> are set; otherwise false.</param> | ||
| 1025 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1026 | public static bool CheckBits(this byte source, byte bits, bool allBits) | ||
| 1027 | { | ||
| 1028 | return (allBits ? ((source & bits) == bits) : ((source & bits) != 0)); | ||
| 1029 | } | ||
| 1030 | |||
| 1031 | /// <summary> | ||
| 1032 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1033 | /// </summary> | ||
| 1034 | /// <param name="source">Value source.</param> | ||
| 1035 | /// <param name="bits"><see cref="Bits"/> to check.</param> | ||
| 1036 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1037 | [CLSCompliant(false)] | ||
| 1038 | public static bool CheckBits(this short source, Bits bits) | ||
| 1039 | { | ||
| 1040 | checked | ||
| 1041 | { | ||
| 1042 | return CheckBits(source, (short)bits); | ||
| 1043 | } | ||
| 1044 | } | ||
| 1045 | |||
| 1046 | /// <summary> | ||
| 1047 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1048 | /// </summary> | ||
| 1049 | /// <param name="source">Value source.</param> | ||
| 1050 | /// <param name="bits">Bit-mask of the bits to check.</param> | ||
| 1051 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1052 | public static bool CheckBits(this short source, short bits) | ||
| 1053 | { | ||
| 1054 | return CheckBits(source, bits, true); | ||
| 1055 | } | ||
| 1056 | |||
| 1057 | /// <summary> | ||
| 1058 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1059 | /// </summary> | ||
| 1060 | /// <param name="source">Value source.</param> | ||
| 1061 | /// <param name="bits"><see cref="Bits"/> to check.</param> | ||
| 1062 | /// <param name="allBits">true to check if all <paramref name="bits"/> are set; otherwise false.</param> | ||
| 1063 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1064 | [CLSCompliant(false)] | ||
| 1065 | public static bool CheckBits(this short source, Bits bits, bool allBits) | ||
| 1066 | { | ||
| 1067 | checked | ||
| 1068 | { | ||
| 1069 | return CheckBits(source, (short)bits, allBits); | ||
| 1070 | } | ||
| 1071 | } | ||
| 1072 | |||
| 1073 | /// <summary> | ||
| 1074 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1075 | /// </summary> | ||
| 1076 | /// <param name="source">Value source.</param> | ||
| 1077 | /// <param name="bits">Bit-mask of the bits to check.</param> | ||
| 1078 | /// <param name="allBits">true to check if all <paramref name="bits"/> are set; otherwise false.</param> | ||
| 1079 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1080 | public static bool CheckBits(this short source, short bits, bool allBits) | ||
| 1081 | { | ||
| 1082 | return (allBits ? ((source & bits) == bits) : ((source & bits) != 0)); | ||
| 1083 | } | ||
| 1084 | |||
| 1085 | /// <summary> | ||
| 1086 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1087 | /// </summary> | ||
| 1088 | /// <param name="source">Value source.</param> | ||
| 1089 | /// <param name="bits"><see cref="Bits"/> to check.</param> | ||
| 1090 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1091 | [CLSCompliant(false)] | ||
| 1092 | public static bool CheckBits(this ushort source, Bits bits) | ||
| 1093 | { | ||
| 1094 | checked | ||
| 1095 | { | ||
| 1096 | return CheckBits(source, (ushort)bits); | ||
| 1097 | } | ||
| 1098 | } | ||
| 1099 | |||
| 1100 | /// <summary> | ||
| 1101 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1102 | /// </summary> | ||
| 1103 | /// <param name="source">Value source.</param> | ||
| 1104 | /// <param name="bits">Bit-mask of the bits to check.</param> | ||
| 1105 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1106 | [CLSCompliant(false)] | ||
| 1107 | public static bool CheckBits(this ushort source, ushort bits) | ||
| 1108 | { | ||
| 1109 | return CheckBits(source, bits, true); | ||
| 1110 | } | ||
| 1111 | |||
| 1112 | /// <summary> | ||
| 1113 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1114 | /// </summary> | ||
| 1115 | /// <param name="source">Value source.</param> | ||
| 1116 | /// <param name="bits"><see cref="Bits"/> to check.</param> | ||
| 1117 | /// <param name="allBits">true to check if all <paramref name="bits"/> are set; otherwise false.</param> | ||
| 1118 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1119 | [CLSCompliant(false)] | ||
| 1120 | public static bool CheckBits(this ushort source, Bits bits, bool allBits) | ||
| 1121 | { | ||
| 1122 | checked | ||
| 1123 | { | ||
| 1124 | return CheckBits(source, (ushort)bits, allBits); | ||
| 1125 | } | ||
| 1126 | } | ||
| 1127 | |||
| 1128 | /// <summary> | ||
| 1129 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1130 | /// </summary> | ||
| 1131 | /// <param name="source">Value source.</param> | ||
| 1132 | /// <param name="bits">Bit-mask of the bits to check.</param> | ||
| 1133 | /// <param name="allBits">true to check if all <paramref name="bits"/> are set; otherwise false.</param> | ||
| 1134 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1135 | [CLSCompliant(false)] | ||
| 1136 | public static bool CheckBits(this ushort source, ushort bits, bool allBits) | ||
| 1137 | { | ||
| 1138 | return (allBits ? ((source & bits) == bits) : ((source & bits) != 0)); | ||
| 1139 | } | ||
| 1140 | |||
| 1141 | /// <summary> | ||
| 1142 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1143 | /// </summary> | ||
| 1144 | /// <param name="source">Value source.</param> | ||
| 1145 | /// <param name="bits"><see cref="Bits"/> to check.</param> | ||
| 1146 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1147 | [CLSCompliant(false)] | ||
| 1148 | public static bool CheckBits(this Int24 source, Bits bits) | ||
| 1149 | { | ||
| 1150 | checked | ||
| 1151 | { | ||
| 1152 | return CheckBits(source, (Int24)bits); | ||
| 1153 | } | ||
| 1154 | } | ||
| 1155 | |||
| 1156 | /// <summary> | ||
| 1157 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1158 | /// </summary> | ||
| 1159 | /// <param name="source">Value source.</param> | ||
| 1160 | /// <param name="bits">Bit-mask of the bits to check.</param> | ||
| 1161 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1162 | public static bool CheckBits(this Int24 source, Int24 bits) | ||
| 1163 | { | ||
| 1164 | return CheckBits(source, bits, true); | ||
| 1165 | } | ||
| 1166 | |||
| 1167 | /// <summary> | ||
| 1168 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1169 | /// </summary> | ||
| 1170 | /// <param name="source">Value source.</param> | ||
| 1171 | /// <param name="bits"><see cref="Bits"/> to check.</param> | ||
| 1172 | /// <param name="allBits">true to check if all <paramref name="bits"/> are set; otherwise false.</param> | ||
| 1173 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1174 | [CLSCompliant(false)] | ||
| 1175 | public static bool CheckBits(this Int24 source, Bits bits, bool allBits) | ||
| 1176 | { | ||
| 1177 | checked | ||
| 1178 | { | ||
| 1179 | return CheckBits(source, (Int24)bits, allBits); | ||
| 1180 | } | ||
| 1181 | } | ||
| 1182 | |||
| 1183 | /// <summary> | ||
| 1184 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1185 | /// </summary> | ||
| 1186 | /// <param name="source">Value source.</param> | ||
| 1187 | /// <param name="bits">Bit-mask of the bits to check.</param> | ||
| 1188 | /// <param name="allBits">true to check if all <paramref name="bits"/> are set; otherwise false.</param> | ||
| 1189 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1190 | public static bool CheckBits(this Int24 source, Int24 bits, bool allBits) | ||
| 1191 | { | ||
| 1192 | return (allBits ? ((source & bits) == bits) : ((source & bits) != 0)); | ||
| 1193 | } | ||
| 1194 | |||
| 1195 | /// <summary> | ||
| 1196 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1197 | /// </summary> | ||
| 1198 | /// <param name="source">Value source.</param> | ||
| 1199 | /// <param name="bits"><see cref="Bits"/> to check.</param> | ||
| 1200 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1201 | [CLSCompliant(false)] | ||
| 1202 | public static bool CheckBits(this UInt24 source, Bits bits) | ||
| 1203 | { | ||
| 1204 | checked | ||
| 1205 | { | ||
| 1206 | return CheckBits(source, (UInt24)bits); | ||
| 1207 | } | ||
| 1208 | } | ||
| 1209 | |||
| 1210 | /// <summary> | ||
| 1211 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1212 | /// </summary> | ||
| 1213 | /// <param name="source">Value source.</param> | ||
| 1214 | /// <param name="bits">Bit-mask of the bits to check.</param> | ||
| 1215 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1216 | [CLSCompliant(false)] | ||
| 1217 | public static bool CheckBits(this UInt24 source, UInt24 bits) | ||
| 1218 | { | ||
| 1219 | return CheckBits(source, bits, true); | ||
| 1220 | } | ||
| 1221 | |||
| 1222 | /// <summary> | ||
| 1223 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1224 | /// </summary> | ||
| 1225 | /// <param name="source">Value source.</param> | ||
| 1226 | /// <param name="bits"><see cref="Bits"/> to check.</param> | ||
| 1227 | /// <param name="allBits">true to check if all <paramref name="bits"/> are set; otherwise false.</param> | ||
| 1228 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1229 | [CLSCompliant(false)] | ||
| 1230 | public static bool CheckBits(this UInt24 source, Bits bits, bool allBits) | ||
| 1231 | { | ||
| 1232 | checked | ||
| 1233 | { | ||
| 1234 | return CheckBits(source, (UInt24)bits, allBits); | ||
| 1235 | } | ||
| 1236 | } | ||
| 1237 | |||
| 1238 | /// <summary> | ||
| 1239 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1240 | /// </summary> | ||
| 1241 | /// <param name="source">Value source.</param> | ||
| 1242 | /// <param name="bits">Bit-mask of the bits to check.</param> | ||
| 1243 | /// <param name="allBits">true to check if all <paramref name="bits"/> are set; otherwise false.</param> | ||
| 1244 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1245 | [CLSCompliant(false)] | ||
| 1246 | public static bool CheckBits(this UInt24 source, UInt24 bits, bool allBits) | ||
| 1247 | { | ||
| 1248 | return (allBits ? ((source & bits) == bits) : ((source & bits) != 0)); | ||
| 1249 | } | ||
| 1250 | |||
| 1251 | /// <summary> | ||
| 1252 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1253 | /// </summary> | ||
| 1254 | /// <param name="source">Value source.</param> | ||
| 1255 | /// <param name="bits"><see cref="Bits"/> to check.</param> | ||
| 1256 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1257 | [CLSCompliant(false)] | ||
| 1258 | public static bool CheckBits(this int source, Bits bits) | ||
| 1259 | { | ||
| 1260 | checked | ||
| 1261 | { | ||
| 1262 | return CheckBits(source, (int)bits); | ||
| 1263 | } | ||
| 1264 | } | ||
| 1265 | |||
| 1266 | /// <summary> | ||
| 1267 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1268 | /// </summary> | ||
| 1269 | /// <param name="source">Value source.</param> | ||
| 1270 | /// <param name="bits">Bit-mask of the bits to check.</param> | ||
| 1271 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1272 | public static bool CheckBits(this int source, int bits) | ||
| 1273 | { | ||
| 1274 | return CheckBits(source, bits, true); | ||
| 1275 | } | ||
| 1276 | |||
| 1277 | /// <summary> | ||
| 1278 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1279 | /// </summary> | ||
| 1280 | /// <param name="source">Value source.</param> | ||
| 1281 | /// <param name="bits"><see cref="Bits"/> to check.</param> | ||
| 1282 | /// <param name="allBits">true to check if all <paramref name="bits"/> are set; otherwise false.</param> | ||
| 1283 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1284 | [CLSCompliant(false)] | ||
| 1285 | public static bool CheckBits(this int source, Bits bits, bool allBits) | ||
| 1286 | { | ||
| 1287 | checked | ||
| 1288 | { | ||
| 1289 | return CheckBits(source, (int)bits, allBits); | ||
| 1290 | } | ||
| 1291 | } | ||
| 1292 | |||
| 1293 | /// <summary> | ||
| 1294 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1295 | /// </summary> | ||
| 1296 | /// <param name="source">Value source.</param> | ||
| 1297 | /// <param name="bits">Bit-mask of the bits to check.</param> | ||
| 1298 | /// <param name="allBits">true to check if all <paramref name="bits"/> are set; otherwise false.</param> | ||
| 1299 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1300 | public static bool CheckBits(this int source, int bits, bool allBits) | ||
| 1301 | { | ||
| 1302 | return (allBits ? ((source & bits) == bits) : ((source & bits) != 0)); | ||
| 1303 | } | ||
| 1304 | |||
| 1305 | /// <summary> | ||
| 1306 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1307 | /// </summary> | ||
| 1308 | /// <param name="source">Value source.</param> | ||
| 1309 | /// <param name="bits"><see cref="Bits"/> to check.</param> | ||
| 1310 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1311 | [CLSCompliant(false)] | ||
| 1312 | public static bool CheckBits(this uint source, Bits bits) | ||
| 1313 | { | ||
| 1314 | checked | ||
| 1315 | { | ||
| 1316 | return CheckBits(source, (uint)bits); | ||
| 1317 | } | ||
| 1318 | } | ||
| 1319 | |||
| 1320 | /// <summary> | ||
| 1321 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1322 | /// </summary> | ||
| 1323 | /// <param name="source">Value source.</param> | ||
| 1324 | /// <param name="bits">Bit-mask of the bits to check.</param> | ||
| 1325 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1326 | [CLSCompliant(false)] | ||
| 1327 | public static bool CheckBits(this uint source, uint bits) | ||
| 1328 | { | ||
| 1329 | return CheckBits(source, bits, true); | ||
| 1330 | } | ||
| 1331 | |||
| 1332 | /// <summary> | ||
| 1333 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1334 | /// </summary> | ||
| 1335 | /// <param name="source">Value source.</param> | ||
| 1336 | /// <param name="bits"><see cref="Bits"/> to check.</param> | ||
| 1337 | /// <param name="allBits">true to check if all <paramref name="bits"/> are set; otherwise false.</param> | ||
| 1338 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1339 | [CLSCompliant(false)] | ||
| 1340 | public static bool CheckBits(this uint source, Bits bits, bool allBits) | ||
| 1341 | { | ||
| 1342 | checked | ||
| 1343 | { | ||
| 1344 | return CheckBits(source, (uint)bits, allBits); | ||
| 1345 | } | ||
| 1346 | } | ||
| 1347 | |||
| 1348 | /// <summary> | ||
| 1349 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1350 | /// </summary> | ||
| 1351 | /// <param name="source">Value source.</param> | ||
| 1352 | /// <param name="bits">Bit-mask of the bits to check.</param> | ||
| 1353 | /// <param name="allBits">true to check if all <paramref name="bits"/> are set; otherwise false.</param> | ||
| 1354 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1355 | [CLSCompliant(false)] | ||
| 1356 | public static bool CheckBits(this uint source, uint bits, bool allBits) | ||
| 1357 | { | ||
| 1358 | return (allBits ? ((source & bits) == bits) : ((source & bits) != 0)); | ||
| 1359 | } | ||
| 1360 | |||
| 1361 | /// <summary> | ||
| 1362 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1363 | /// </summary> | ||
| 1364 | /// <param name="source">Value source.</param> | ||
| 1365 | /// <param name="bits"><see cref="Bits"/> to check.</param> | ||
| 1366 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1367 | [CLSCompliant(false)] | ||
| 1368 | public static bool CheckBits(this long source, Bits bits) | ||
| 1369 | { | ||
| 1370 | checked | ||
| 1371 | { | ||
| 1372 | return CheckBits(source, (long)bits); | ||
| 1373 | } | ||
| 1374 | } | ||
| 1375 | |||
| 1376 | /// <summary> | ||
| 1377 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1378 | /// </summary> | ||
| 1379 | /// <param name="source">Value source.</param> | ||
| 1380 | /// <param name="bits">Bit-mask of the bits to check.</param> | ||
| 1381 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1382 | public static bool CheckBits(this long source, long bits) | ||
| 1383 | { | ||
| 1384 | return CheckBits(source, bits, true); | ||
| 1385 | } | ||
| 1386 | |||
| 1387 | /// <summary> | ||
| 1388 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1389 | /// </summary> | ||
| 1390 | /// <param name="source">Value source.</param> | ||
| 1391 | /// <param name="bits"><see cref="Bits"/> to check.</param> | ||
| 1392 | /// <param name="allBits">true to check if all <paramref name="bits"/> are set; otherwise false.</param> | ||
| 1393 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1394 | [CLSCompliant(false)] | ||
| 1395 | public static bool CheckBits(this long source, Bits bits, bool allBits) | ||
| 1396 | { | ||
| 1397 | checked | ||
| 1398 | { | ||
| 1399 | return CheckBits(source, (long)bits, allBits); | ||
| 1400 | } | ||
| 1401 | } | ||
| 1402 | |||
| 1403 | /// <summary> | ||
| 1404 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1405 | /// </summary> | ||
| 1406 | /// <param name="source">Value source.</param> | ||
| 1407 | /// <param name="bits">Bit-mask of the bits to check.</param> | ||
| 1408 | /// <param name="allBits">true to check if all <paramref name="bits"/> are set; otherwise false.</param> | ||
| 1409 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1410 | public static bool CheckBits(this long source, long bits, bool allBits) | ||
| 1411 | { | ||
| 1412 | return (allBits ? ((source & bits) == bits) : ((source & bits) != 0)); | ||
| 1413 | } | ||
| 1414 | |||
| 1415 | /// <summary> | ||
| 1416 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1417 | /// </summary> | ||
| 1418 | /// <param name="source">Value source.</param> | ||
| 1419 | /// <param name="bits"><see cref="Bits"/> to check.</param> | ||
| 1420 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1421 | [CLSCompliant(false)] | ||
| 1422 | public static bool CheckBits(this ulong source, Bits bits) | ||
| 1423 | { | ||
| 1424 | checked | ||
| 1425 | { | ||
| 1426 | return CheckBits(source, (ulong)bits); | ||
| 1427 | } | ||
| 1428 | } | ||
| 1429 | |||
| 1430 | /// <summary> | ||
| 1431 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1432 | /// </summary> | ||
| 1433 | /// <param name="source">Value source.</param> | ||
| 1434 | /// <param name="bits">Bit-mask of the bits to check.</param> | ||
| 1435 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1436 | [CLSCompliant(false)] | ||
| 1437 | public static bool CheckBits(this ulong source, ulong bits) | ||
| 1438 | { | ||
| 1439 | return CheckBits(source, bits, true); | ||
| 1440 | } | ||
| 1441 | |||
| 1442 | /// <summary> | ||
| 1443 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1444 | /// </summary> | ||
| 1445 | /// <param name="source">Value source.</param> | ||
| 1446 | /// <param name="bits"><see cref="Bits"/> to check.</param> | ||
| 1447 | /// <param name="allBits">true to check if all <paramref name="bits"/> are set; otherwise false.</param> | ||
| 1448 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1449 | [CLSCompliant(false)] | ||
| 1450 | public static bool CheckBits(this ulong source, Bits bits, bool allBits) | ||
| 1451 | { | ||
| 1452 | checked | ||
| 1453 | { | ||
| 1454 | return CheckBits(source, (ulong)bits, allBits); | ||
| 1455 | } | ||
| 1456 | } | ||
| 1457 | |||
| 1458 | /// <summary> | ||
| 1459 | /// Determines if specified <paramref name="bits"/> are set. | ||
| 1460 | /// </summary> | ||
| 1461 | /// <param name="source">Value source.</param> | ||
| 1462 | /// <param name="bits">Bit-mask of the bits to check.</param> | ||
| 1463 | /// <param name="allBits">true to check if all <paramref name="bits"/> are set; otherwise false.</param> | ||
| 1464 | /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> | ||
| 1465 | [CLSCompliant(false)] | ||
| 1466 | public static bool CheckBits(this ulong source, ulong bits, bool allBits) | ||
| 1467 | { | ||
| 1468 | return (allBits ? ((source & bits) == bits) : ((source & bits) != 0)); | ||
| 1469 | } | ||
| 1470 | |||
| 1471 | #endregion | ||
| 1472 | |||
| 1473 | #region [ ToggleBits Extensions ] | ||
| 1474 | |||
| 1475 | /// <summary> | ||
| 1476 | /// Returns value with specified <paramref name="bits"/> toggled. | ||
| 1477 | /// </summary> | ||
| 1478 | /// <param name="source">Value source.</param> | ||
| 1479 | /// <param name="bits"><see cref="Bits"/> to toggle.</param> | ||
| 1480 | /// <returns><see cref="sbyte"/> value with specified <paramref name="bits"/> toggled.</returns> | ||
| 1481 | [CLSCompliant(false)] | ||
| 1482 | public static sbyte ToggleBits(this sbyte source, Bits bits) | ||
| 1483 | { | ||
| 1484 | checked | ||
| 1485 | { | ||
| 1486 | return ToggleBits(source, (sbyte)bits); | ||
| 1487 | } | ||
| 1488 | } | ||
| 1489 | |||
| 1490 | /// <summary> | ||
| 1491 | /// Returns value with specified <paramref name="bits"/> toggled. | ||
| 1492 | /// </summary> | ||
| 1493 | /// <param name="source">Value source.</param> | ||
| 1494 | /// <param name="bits">Bit-mask of the bits to toggle.</param> | ||
| 1495 | /// <returns><see cref="sbyte"/> value with specified <paramref name="bits"/> toggled.</returns> | ||
| 1496 | [CLSCompliant(false)] | ||
| 1497 | public static sbyte ToggleBits(this sbyte source, sbyte bits) | ||
| 1498 | { | ||
| 1499 | return ((sbyte)(source ^ bits)); | ||
| 1500 | } | ||
| 1501 | |||
| 1502 | /// <summary> | ||
| 1503 | /// Returns value with specified <paramref name="bits"/> toggled. | ||
| 1504 | /// </summary> | ||
| 1505 | /// <param name="source">Value source.</param> | ||
| 1506 | /// <param name="bits"><see cref="Bits"/> to toggle.</param> | ||
| 1507 | /// <returns><see cref="byte"/> value with specified <paramref name="bits"/> toggled.</returns> | ||
| 1508 | [CLSCompliant(false)] | ||
| 1509 | public static byte ToggleBits(this byte source, Bits bits) | ||
| 1510 | { | ||
| 1511 | checked | ||
| 1512 | { | ||
| 1513 | return ToggleBits(source, (byte)bits); | ||
| 1514 | } | ||
| 1515 | } | ||
| 1516 | |||
| 1517 | /// <summary> | ||
| 1518 | /// Returns value with specified <paramref name="bits"/> toggled. | ||
| 1519 | /// </summary> | ||
| 1520 | /// <param name="source">Value source.</param> | ||
| 1521 | /// <param name="bits">Bit-mask of the bits to toggle.</param> | ||
| 1522 | /// <returns><see cref="byte"/> value with specified <paramref name="bits"/> toggled.</returns> | ||
| 1523 | public static byte ToggleBits(this byte source, byte bits) | ||
| 1524 | { | ||
| 1525 | return ((byte)(source ^ bits)); | ||
| 1526 | } | ||
| 1527 | |||
| 1528 | /// <summary> | ||
| 1529 | /// Returns value with specified <paramref name="bits"/> toggled. | ||
| 1530 | /// </summary> | ||
| 1531 | /// <param name="source">Value source.</param> | ||
| 1532 | /// <param name="bits"><see cref="Bits"/> to toggle.</param> | ||
| 1533 | /// <returns><see cref="short"/> value with specified <paramref name="bits"/> toggled.</returns> | ||
| 1534 | [CLSCompliant(false)] | ||
| 1535 | public static short ToggleBits(this short source, Bits bits) | ||
| 1536 | { | ||
| 1537 | checked | ||
| 1538 | { | ||
| 1539 | return ToggleBits(source, (short)bits); | ||
| 1540 | } | ||
| 1541 | } | ||
| 1542 | |||
| 1543 | /// <summary> | ||
| 1544 | /// Returns value with specified <paramref name="bits"/> toggled. | ||
| 1545 | /// </summary> | ||
| 1546 | /// <param name="source">Value source.</param> | ||
| 1547 | /// <param name="bits">Bit-mask of the bits to toggle.</param> | ||
| 1548 | /// <returns><see cref="short"/> value with specified <paramref name="bits"/> toggled.</returns> | ||
| 1549 | public static short ToggleBits(this short source, short bits) | ||
| 1550 | { | ||
| 1551 | return ((short)(source ^ bits)); | ||
| 1552 | } | ||
| 1553 | |||
| 1554 | /// <summary> | ||
| 1555 | /// Returns value with specified <paramref name="bits"/> toggled. | ||
| 1556 | /// </summary> | ||
| 1557 | /// <param name="source">Value source.</param> | ||
| 1558 | /// <param name="bits"><see cref="Bits"/> to toggle.</param> | ||
| 1559 | /// <returns><see cref="ushort"/> value with specified <paramref name="bits"/> toggled.</returns> | ||
| 1560 | [CLSCompliant(false)] | ||
| 1561 | public static ushort ToggleBits(this ushort source, Bits bits) | ||
| 1562 | { | ||
| 1563 | checked | ||
| 1564 | { | ||
| 1565 | return ToggleBits(source, (ushort)bits); | ||
| 1566 | } | ||
| 1567 | } | ||
| 1568 | |||
| 1569 | /// <summary> | ||
| 1570 | /// Returns value with specified <paramref name="bits"/> toggled. | ||
| 1571 | /// </summary> | ||
| 1572 | /// <param name="source">Value source.</param> | ||
| 1573 | /// <param name="bits">Bit-mask of the bits to toggle.</param> | ||
| 1574 | /// <returns><see cref="ushort"/> value with specified <paramref name="bits"/> toggled.</returns> | ||
| 1575 | [CLSCompliant(false)] | ||
| 1576 | public static ushort ToggleBits(this ushort source, ushort bits) | ||
| 1577 | { | ||
| 1578 | return ((ushort)(source ^ bits)); | ||
| 1579 | } | ||
| 1580 | |||
| 1581 | /// <summary> | ||
| 1582 | /// Returns value with specified <paramref name="bits"/> toggled. | ||
| 1583 | /// </summary> | ||
| 1584 | /// <param name="source">Value source.</param> | ||
| 1585 | /// <param name="bits"><see cref="Bits"/> to toggle.</param> | ||
| 1586 | /// <returns><see cref="Int24"/> value with specified <paramref name="bits"/> toggled.</returns> | ||
| 1587 | [CLSCompliant(false)] | ||
| 1588 | public static Int24 ToggleBits(this Int24 source, Bits bits) | ||
| 1589 | { | ||
| 1590 | checked | ||
| 1591 | { | ||
| 1592 | return ToggleBits(source, (Int24)bits); | ||
| 1593 | } | ||
| 1594 | } | ||
| 1595 | |||
| 1596 | /// <summary> | ||
| 1597 | /// Returns value with specified <paramref name="bits"/> toggled. | ||
| 1598 | /// </summary> | ||
| 1599 | /// <param name="source">Value source.</param> | ||
| 1600 | /// <param name="bits">Bit-mask of the bits to toggle.</param> | ||
| 1601 | /// <returns><see cref="Int24"/> value with specified <paramref name="bits"/> toggled.</returns> | ||
| 1602 | public static Int24 ToggleBits(this Int24 source, Int24 bits) | ||
| 1603 | { | ||
| 1604 | return (source ^ bits); | ||
| 1605 | } | ||
| 1606 | |||
| 1607 | /// <summary> | ||
| 1608 | /// Returns value with specified <paramref name="bits"/> toggled. | ||
| 1609 | /// </summary> | ||
| 1610 | /// <param name="source">Value source.</param> | ||
| 1611 | /// <param name="bits"><see cref="Bits"/> to toggle.</param> | ||
| 1612 | /// <returns><see cref="UInt24"/> value with specified <paramref name="bits"/> toggled.</returns> | ||
| 1613 | [CLSCompliant(false)] | ||
| 1614 | public static UInt24 ToggleBits(this UInt24 source, Bits bits) | ||
| 1615 | { | ||
| 1616 | checked | ||
| 1617 | { | ||
| 1618 | return ToggleBits(source, (UInt24)bits); | ||
| 1619 | } | ||
| 1620 | } | ||
| 1621 | |||
| 1622 | /// <summary> | ||
| 1623 | /// Returns value with specified <paramref name="bits"/> toggled. | ||
| 1624 | /// </summary> | ||
| 1625 | /// <param name="source">Value source.</param> | ||
| 1626 | /// <param name="bits">Bit-mask of the bits to toggle.</param> | ||
| 1627 | /// <returns><see cref="UInt24"/> value with specified <paramref name="bits"/> toggled.</returns> | ||
| 1628 | [CLSCompliant(false)] | ||
| 1629 | public static UInt24 ToggleBits(this UInt24 source, UInt24 bits) | ||
| 1630 | { | ||
| 1631 | return (source ^ bits); | ||
| 1632 | } | ||
| 1633 | |||
| 1634 | /// <summary> | ||
| 1635 | /// Returns value with specified <paramref name="bits"/> toggled. | ||
| 1636 | /// </summary> | ||
| 1637 | /// <param name="source">Value source.</param> | ||
| 1638 | /// <param name="bits"><see cref="Bits"/> to toggle.</param> | ||
| 1639 | /// <returns><see cref="int"/> value with specified <paramref name="bits"/> toggled.</returns> | ||
| 1640 | [CLSCompliant(false)] | ||
| 1641 | public static int ToggleBits(this int source, Bits bits) | ||
| 1642 | { | ||
| 1643 | checked | ||
| 1644 | { | ||
| 1645 | return ToggleBits(source, (int)bits); | ||
| 1646 | } | ||
| 1647 | } | ||
| 1648 | |||
| 1649 | /// <summary> | ||
| 1650 | /// Returns value with specified <paramref name="bits"/> toggled. | ||
| 1651 | /// </summary> | ||
| 1652 | /// <param name="source">Value source.</param> | ||
| 1653 | /// <param name="bits">Bit-mask of the bits to toggle.</param> | ||
| 1654 | /// <returns><see cref="int"/> value with specified <paramref name="bits"/> toggled.</returns> | ||
| 1655 | public static int ToggleBits(this int source, int bits) | ||
| 1656 | { | ||
| 1657 | return (source ^ bits); | ||
| 1658 | } | ||
| 1659 | |||
| 1660 | /// <summary> | ||
| 1661 | /// Returns value with specified <paramref name="bits"/> toggled. | ||
| 1662 | /// </summary> | ||
| 1663 | /// <param name="source">Value source.</param> | ||
| 1664 | /// <param name="bits"><see cref="Bits"/> to toggle.</param> | ||
| 1665 | /// <returns><see cref="uint"/> value with specified <paramref name="bits"/> toggled.</returns> | ||
| 1666 | [CLSCompliant(false)] | ||
| 1667 | public static uint ToggleBits(this uint source, Bits bits) | ||
| 1668 | { | ||
| 1669 | checked | ||
| 1670 | { | ||
| 1671 | return ToggleBits(source, (uint)bits); | ||
| 1672 | } | ||
| 1673 | } | ||
| 1674 | |||
| 1675 | /// <summary> | ||
| 1676 | /// Returns value with specified <paramref name="bits"/> toggled. | ||
| 1677 | /// </summary> | ||
| 1678 | /// <param name="source">Value source.</param> | ||
| 1679 | /// <param name="bits">Bit-mask of the bits to toggle.</param> | ||
| 1680 | /// <returns><see cref="uint"/> value with specified <paramref name="bits"/> toggled.</returns> | ||
| 1681 | [CLSCompliant(false)] | ||
| 1682 | public static uint ToggleBits(this uint source, uint bits) | ||
| 1683 | { | ||
| 1684 | return (source ^ bits); | ||
| 1685 | } | ||
| 1686 | |||
| 1687 | /// <summary> | ||
| 1688 | /// Returns value with specified <paramref name="bits"/> toggled. | ||
| 1689 | /// </summary> | ||
| 1690 | /// <param name="source">Value source.</param> | ||
| 1691 | /// <param name="bits"><see cref="Bits"/> to toggle.</param> | ||
| 1692 | /// <returns><see cref="long"/> value with specified <paramref name="bits"/> toggled.</returns> | ||
| 1693 | [CLSCompliant(false)] | ||
| 1694 | public static long ToggleBits(this long source, Bits bits) | ||
| 1695 | { | ||
| 1696 | checked | ||
| 1697 | { | ||
| 1698 | return ToggleBits(source, (long)bits); | ||
| 1699 | } | ||
| 1700 | } | ||
| 1701 | |||
| 1702 | /// <summary> | ||
| 1703 | /// Returns value with specified <paramref name="bits"/> toggled. | ||
| 1704 | /// </summary> | ||
| 1705 | /// <param name="source">Value source.</param> | ||
| 1706 | /// <param name="bits">Bit-mask of the bits to toggle.</param> | ||
| 1707 | /// <returns><see cref="long"/> value with specified <paramref name="bits"/> toggled.</returns> | ||
| 1708 | public static long ToggleBits(this long source, long bits) | ||
| 1709 | { | ||
| 1710 | return (source ^ bits); | ||
| 1711 | } | ||
| 1712 | |||
| 1713 | /// <summary> | ||
| 1714 | /// Returns value with specified <paramref name="bits"/> toggled. | ||
| 1715 | /// </summary> | ||
| 1716 | /// <param name="source">Value source.</param> | ||
| 1717 | /// <param name="bits"><see cref="Bits"/> to toggle.</param> | ||
| 1718 | /// <returns><see cref="ulong"/> value with specified <paramref name="bits"/> toggled.</returns> | ||
| 1719 | [CLSCompliant(false)] | ||
| 1720 | public static ulong ToggleBits(this ulong source, Bits bits) | ||
| 1721 | { | ||
| 1722 | checked | ||
| 1723 | { | ||
| 1724 | return ToggleBits(source, (ulong)bits); | ||
| 1725 | } | ||
| 1726 | } | ||
| 1727 | |||
| 1728 | /// <summary> | ||
| 1729 | /// Returns value with specified <paramref name="bits"/> toggled. | ||
| 1730 | /// </summary> | ||
| 1731 | /// <param name="source">Value source.</param> | ||
| 1732 | /// <param name="bits">Bit-mask of the bits to toggle.</param> | ||
| 1733 | /// <returns><see cref="ulong"/> value with specified <paramref name="bits"/> toggled.</returns> | ||
| 1734 | [CLSCompliant(false)] | ||
| 1735 | public static ulong ToggleBits(this ulong source, ulong bits) | ||
| 1736 | { | ||
| 1737 | return (source ^ bits); | ||
| 1738 | } | ||
| 1739 | |||
| 1740 | #endregion | ||
| 1741 | |||
| 1742 | #region [ GetMaskedValue Extensions ] | ||
| 1743 | |||
| 1744 | /// <summary> | ||
| 1745 | /// Returns value stored in the bits represented by the specified <paramref name="bitmask"/>. | ||
| 1746 | /// </summary> | ||
| 1747 | /// <param name="source">Value source.</param> | ||
| 1748 | /// <param name="bitmask"><see cref="Bits"/> that make-up the bit-mask.</param> | ||
| 1749 | /// <returns><see cref="sbyte"/> value.</returns> | ||
| 1750 | [CLSCompliant(false)] | ||
| 1751 | public static sbyte GetMaskedValue(this sbyte source, Bits bitmask) | ||
| 1752 | { | ||
| 1753 | checked | ||
| 1754 | { | ||
| 1755 | return GetMaskedValue(source, (sbyte)bitmask); | ||
| 1756 | } | ||
| 1757 | } | ||
| 1758 | |||
| 1759 | /// <summary> | ||
| 1760 | /// Returns value stored in the bits represented by the specified <paramref name="bitmask"/>. | ||
| 1761 | /// </summary> | ||
| 1762 | /// <param name="source">Value source.</param> | ||
| 1763 | /// <param name="bitmask">Bit-mask of the bits involved.</param> | ||
| 1764 | /// <returns><see cref="sbyte"/> value.</returns> | ||
| 1765 | [CLSCompliant(false)] | ||
| 1766 | public static sbyte GetMaskedValue(this sbyte source, sbyte bitmask) | ||
| 1767 | { | ||
| 1768 | return ((sbyte)(source & bitmask)); | ||
| 1769 | } | ||
| 1770 | |||
| 1771 | /// <summary> | ||
| 1772 | /// Returns value stored in the bits represented by the specified <paramref name="bitmask"/>. | ||
| 1773 | /// </summary> | ||
| 1774 | /// <param name="source">Value source.</param> | ||
| 1775 | /// <param name="bitmask"><see cref="Bits"/> that make-up the bit-mask.</param> | ||
| 1776 | /// <returns><see cref="byte"/> value.</returns> | ||
| 1777 | [CLSCompliant(false)] | ||
| 1778 | public static byte GetMaskedValue(this byte source, Bits bitmask) | ||
| 1779 | { | ||
| 1780 | checked | ||
| 1781 | { | ||
| 1782 | return GetMaskedValue(source, (byte)bitmask); | ||
| 1783 | } | ||
| 1784 | } | ||
| 1785 | |||
| 1786 | /// <summary> | ||
| 1787 | /// Returns value stored in the bits represented by the specified <paramref name="bitmask"/>. | ||
| 1788 | /// </summary> | ||
| 1789 | /// <param name="source">Value source.</param> | ||
| 1790 | /// <param name="bitmask">Bit-mask of the bits involved.</param> | ||
| 1791 | /// <returns><see cref="byte"/> value.</returns> | ||
| 1792 | public static byte GetMaskedValue(this byte source, byte bitmask) | ||
| 1793 | { | ||
| 1794 | return ((byte)(source & bitmask)); | ||
| 1795 | } | ||
| 1796 | |||
| 1797 | /// <summary> | ||
| 1798 | /// Returns value stored in the bits represented by the specified <paramref name="bitmask"/>. | ||
| 1799 | /// </summary> | ||
| 1800 | /// <param name="source">Value source.</param> | ||
| 1801 | /// <param name="bitmask"><see cref="Bits"/> that make-up the bit-mask.</param> | ||
| 1802 | /// <returns><see cref="short"/> value.</returns> | ||
| 1803 | [CLSCompliant(false)] | ||
| 1804 | public static short GetMaskedValue(this short source, Bits bitmask) | ||
| 1805 | { | ||
| 1806 | checked | ||
| 1807 | { | ||
| 1808 | return GetMaskedValue(source, (short)bitmask); | ||
| 1809 | } | ||
| 1810 | } | ||
| 1811 | |||
| 1812 | /// <summary> | ||
| 1813 | /// Returns value stored in the bits represented by the specified <paramref name="bitmask"/>. | ||
| 1814 | /// </summary> | ||
| 1815 | /// <param name="source">Value source.</param> | ||
| 1816 | /// <param name="bitmask">Bit-mask of the bits involved.</param> | ||
| 1817 | /// <returns><see cref="short"/> value.</returns> | ||
| 1818 | public static short GetMaskedValue(this short source, short bitmask) | ||
| 1819 | { | ||
| 1820 | return ((short)(source & bitmask)); | ||
| 1821 | } | ||
| 1822 | |||
| 1823 | /// <summary> | ||
| 1824 | /// Returns value stored in the bits represented by the specified <paramref name="bitmask"/>. | ||
| 1825 | /// </summary> | ||
| 1826 | /// <param name="source">Value source.</param> | ||
| 1827 | /// <param name="bitmask"><see cref="Bits"/> that make-up the bit-mask.</param> | ||
| 1828 | /// <returns><see cref="ushort"/> value.</returns> | ||
| 1829 | [CLSCompliant(false)] | ||
| 1830 | public static ushort GetMaskedValue(this ushort source, Bits bitmask) | ||
| 1831 | { | ||
| 1832 | checked | ||
| 1833 | { | ||
| 1834 | return GetMaskedValue(source, (ushort)bitmask); | ||
| 1835 | } | ||
| 1836 | } | ||
| 1837 | |||
| 1838 | /// <summary> | ||
| 1839 | /// Returns value stored in the bits represented by the specified <paramref name="bitmask"/>. | ||
| 1840 | /// </summary> | ||
| 1841 | /// <param name="source">Value source.</param> | ||
| 1842 | /// <param name="bitmask">Bit-mask of the bits involved.</param> | ||
| 1843 | /// <returns><see cref="ushort"/> value.</returns> | ||
| 1844 | [CLSCompliant(false)] | ||
| 1845 | public static ushort GetMaskedValue(this ushort source, ushort bitmask) | ||
| 1846 | { | ||
| 1847 | return ((ushort)(source & bitmask)); | ||
| 1848 | } | ||
| 1849 | |||
| 1850 | /// <summary> | ||
| 1851 | /// Returns value stored in the bits represented by the specified <paramref name="bitmask"/>. | ||
| 1852 | /// </summary> | ||
| 1853 | /// <param name="source">Value source.</param> | ||
| 1854 | /// <param name="bitmask"><see cref="Bits"/> that make-up the bit-mask.</param> | ||
| 1855 | /// <returns><see cref="Int24"/> value.</returns> | ||
| 1856 | [CLSCompliant(false)] | ||
| 1857 | public static Int24 GetMaskedValue(this Int24 source, Bits bitmask) | ||
| 1858 | { | ||
| 1859 | checked | ||
| 1860 | { | ||
| 1861 | return GetMaskedValue(source, (Int24)bitmask); | ||
| 1862 | } | ||
| 1863 | } | ||
| 1864 | |||
| 1865 | /// <summary> | ||
| 1866 | /// Returns value stored in the bits represented by the specified <paramref name="bitmask"/>. | ||
| 1867 | /// </summary> | ||
| 1868 | /// <param name="source">Value source.</param> | ||
| 1869 | /// <param name="bitmask">Bit-mask of the bits involved.</param> | ||
| 1870 | /// <returns><see cref="Int24"/> value.</returns> | ||
| 1871 | public static Int24 GetMaskedValue(this Int24 source, Int24 bitmask) | ||
| 1872 | { | ||
| 1873 | return (source & bitmask); | ||
| 1874 | } | ||
| 1875 | |||
| 1876 | /// <summary> | ||
| 1877 | /// Returns value stored in the bits represented by the specified <paramref name="bitmask"/>. | ||
| 1878 | /// </summary> | ||
| 1879 | /// <param name="source">Value source.</param> | ||
| 1880 | /// <param name="bitmask"><see cref="Bits"/> that make-up the bit-mask.</param> | ||
| 1881 | /// <returns><see cref="UInt24"/> value.</returns> | ||
| 1882 | [CLSCompliant(false)] | ||
| 1883 | public static UInt24 GetMaskedValue(this UInt24 source, Bits bitmask) | ||
| 1884 | { | ||
| 1885 | checked | ||
| 1886 | { | ||
| 1887 | return GetMaskedValue(source, (UInt24)bitmask); | ||
| 1888 | } | ||
| 1889 | } | ||
| 1890 | |||
| 1891 | /// <summary> | ||
| 1892 | /// Returns value stored in the bits represented by the specified <paramref name="bitmask"/>. | ||
| 1893 | /// </summary> | ||
| 1894 | /// <param name="source">Value source.</param> | ||
| 1895 | /// <param name="bitmask">Bit-mask of the bits involved.</param> | ||
| 1896 | /// <returns><see cref="UInt24"/> value.</returns> | ||
| 1897 | [CLSCompliant(false)] | ||
| 1898 | public static UInt24 GetMaskedValue(this UInt24 source, UInt24 bitmask) | ||
| 1899 | { | ||
| 1900 | return (source & bitmask); | ||
| 1901 | } | ||
| 1902 | |||
| 1903 | /// <summary> | ||
| 1904 | /// Returns value stored in the bits represented by the specified <paramref name="bitmask"/>. | ||
| 1905 | /// </summary> | ||
| 1906 | /// <param name="source">Value source.</param> | ||
| 1907 | /// <param name="bitmask"><see cref="Bits"/> that make-up the bit-mask.</param> | ||
| 1908 | /// <returns><see cref="int"/> value.</returns> | ||
| 1909 | [CLSCompliant(false)] | ||
| 1910 | public static int GetMaskedValue(this int source, Bits bitmask) | ||
| 1911 | { | ||
| 1912 | checked | ||
| 1913 | { | ||
| 1914 | return GetMaskedValue(source, (int)bitmask); | ||
| 1915 | } | ||
| 1916 | } | ||
| 1917 | |||
| 1918 | /// <summary> | ||
| 1919 | /// Returns value stored in the bits represented by the specified <paramref name="bitmask"/>. | ||
| 1920 | /// </summary> | ||
| 1921 | /// <param name="source">Value source.</param> | ||
| 1922 | /// <param name="bitmask">Bit-mask of the bits involved.</param> | ||
| 1923 | /// <returns><see cref="int"/> value.</returns> | ||
| 1924 | public static int GetMaskedValue(this int source, int bitmask) | ||
| 1925 | { | ||
| 1926 | return (source & bitmask); | ||
| 1927 | } | ||
| 1928 | |||
| 1929 | /// <summary> | ||
| 1930 | /// Returns value stored in the bits represented by the specified <paramref name="bitmask"/>. | ||
| 1931 | /// </summary> | ||
| 1932 | /// <param name="source">Value source.</param> | ||
| 1933 | /// <param name="bitmask"><see cref="Bits"/> that make-up the bit-mask.</param> | ||
| 1934 | /// <returns><see cref="uint"/> value.</returns> | ||
| 1935 | [CLSCompliant(false)] | ||
| 1936 | public static uint GetMaskedValue(this uint source, Bits bitmask) | ||
| 1937 | { | ||
| 1938 | checked | ||
| 1939 | { | ||
| 1940 | return GetMaskedValue(source, (uint)bitmask); | ||
| 1941 | } | ||
| 1942 | } | ||
| 1943 | |||
| 1944 | /// <summary> | ||
| 1945 | /// Returns value stored in the bits represented by the specified <paramref name="bitmask"/>. | ||
| 1946 | /// </summary> | ||
| 1947 | /// <param name="source">Value source.</param> | ||
| 1948 | /// <param name="bitmask">Bit-mask of the bits involved.</param> | ||
| 1949 | /// <returns><see cref="uint"/> value.</returns> | ||
| 1950 | [CLSCompliant(false)] | ||
| 1951 | public static uint GetMaskedValue(this uint source, uint bitmask) | ||
| 1952 | { | ||
| 1953 | return (source & bitmask); | ||
| 1954 | } | ||
| 1955 | |||
| 1956 | /// <summary> | ||
| 1957 | /// Returns value stored in the bits represented by the specified <paramref name="bitmask"/>. | ||
| 1958 | /// </summary> | ||
| 1959 | /// <param name="source">Value source.</param> | ||
| 1960 | /// <param name="bitmask"><see cref="Bits"/> that make-up the bit-mask.</param> | ||
| 1961 | /// <returns><see cref="long"/> value.</returns> | ||
| 1962 | [CLSCompliant(false)] | ||
| 1963 | public static long GetMaskedValue(this long source, Bits bitmask) | ||
| 1964 | { | ||
| 1965 | checked | ||
| 1966 | { | ||
| 1967 | return GetMaskedValue(source, (long)bitmask); | ||
| 1968 | } | ||
| 1969 | } | ||
| 1970 | |||
| 1971 | /// <summary> | ||
| 1972 | /// Returns value stored in the bits represented by the specified <paramref name="bitmask"/>. | ||
| 1973 | /// </summary> | ||
| 1974 | /// <param name="source">Value source.</param> | ||
| 1975 | /// <param name="bitmask">Bit-mask of the bits involved.</param> | ||
| 1976 | /// <returns><see cref="long"/> value.</returns> | ||
| 1977 | public static long GetMaskedValue(this long source, long bitmask) | ||
| 1978 | { | ||
| 1979 | return (source & bitmask); | ||
| 1980 | } | ||
| 1981 | |||
| 1982 | /// <summary> | ||
| 1983 | /// Returns value stored in the bits represented by the specified <paramref name="bitmask"/>. | ||
| 1984 | /// </summary> | ||
| 1985 | /// <param name="source">Value source.</param> | ||
| 1986 | /// <param name="bitmask"><see cref="Bits"/> that make-up the bit-mask.</param> | ||
| 1987 | /// <returns><see cref="ulong"/> value.</returns> | ||
| 1988 | [CLSCompliant(false)] | ||
| 1989 | public static ulong GetMaskedValue(this ulong source, Bits bitmask) | ||
| 1990 | { | ||
| 1991 | checked | ||
| 1992 | { | ||
| 1993 | return GetMaskedValue(source, (ulong)bitmask); | ||
| 1994 | } | ||
| 1995 | } | ||
| 1996 | |||
| 1997 | /// <summary> | ||
| 1998 | /// Returns value stored in the bits represented by the specified <paramref name="bitmask"/>. | ||
| 1999 | /// </summary> | ||
| 2000 | /// <param name="source">Value source.</param> | ||
| 2001 | /// <param name="bitmask">Bit-mask of the bits involved.</param> | ||
| 2002 | /// <returns><see cref="ulong"/> value.</returns> | ||
| 2003 | [CLSCompliant(false)] | ||
| 2004 | public static ulong GetMaskedValue(this ulong source, ulong bitmask) | ||
| 2005 | { | ||
| 2006 | return (source & bitmask); | ||
| 2007 | } | ||
| 2008 | |||
| 2009 | #endregion | ||
| 2010 | |||
| 2011 | #region [ SetMaskedValue Extensions ] | ||
| 2012 | |||
| 2013 | /// <summary> | ||
| 2014 | /// Returns value after setting a new <paramref name="value"/> for the bits specified by the <paramref name="bitmask"/>. | ||
| 2015 | /// </summary> | ||
| 2016 | /// <param name="source">Value source.</param> | ||
| 2017 | /// <param name="bitmask"><see cref="Bits"/> that make-up the bit-mask.</param> | ||
| 2018 | /// <param name="value">New value.</param> | ||
| 2019 | /// <returns><see cref="sbyte"/> value.</returns> | ||
| 2020 | [CLSCompliant(false)] | ||
| 2021 | public static sbyte SetMaskedValue(this sbyte source, Bits bitmask, sbyte value) | ||
| 2022 | { | ||
| 2023 | checked | ||
| 2024 | { | ||
| 2025 | return SetMaskedValue(source, (sbyte)bitmask, value); | ||
| 2026 | } | ||
| 2027 | } | ||
| 2028 | |||
| 2029 | /// <summary> | ||
| 2030 | /// Returns value after setting a new <paramref name="value"/> for the bits specified by the <paramref name="bitmask"/>. | ||
| 2031 | /// </summary> | ||
| 2032 | /// <param name="source">Value source.</param> | ||
| 2033 | /// <param name="bitmask">Bit-mask of the bits involved.</param> | ||
| 2034 | /// <param name="value">New value.</param> | ||
| 2035 | /// <returns><see cref="sbyte"/> value.</returns> | ||
| 2036 | [CLSCompliant(false)] | ||
| 2037 | public static sbyte SetMaskedValue(this sbyte source, sbyte bitmask, sbyte value) | ||
| 2038 | { | ||
| 2039 | return ((sbyte)((sbyte)(source & ~bitmask) | value)); | ||
| 2040 | } | ||
| 2041 | |||
| 2042 | /// <summary> | ||
| 2043 | /// Returns value after setting a new <paramref name="value"/> for the bits specified by the <paramref name="bitmask"/>. | ||
| 2044 | /// </summary> | ||
| 2045 | /// <param name="source">Value source.</param> | ||
| 2046 | /// <param name="bitmask"><see cref="Bits"/> that make-up the bit-mask.</param> | ||
| 2047 | /// <param name="value">New value.</param> | ||
| 2048 | /// <returns><see cref="byte"/> value.</returns> | ||
| 2049 | [CLSCompliant(false)] | ||
| 2050 | public static byte SetMaskedValue(this byte source, Bits bitmask, byte value) | ||
| 2051 | { | ||
| 2052 | checked | ||
| 2053 | { | ||
| 2054 | return SetMaskedValue(source, (byte)bitmask, value); | ||
| 2055 | } | ||
| 2056 | } | ||
| 2057 | |||
| 2058 | /// <summary> | ||
| 2059 | /// Returns value after setting a new <paramref name="value"/> for the bits specified by the <paramref name="bitmask"/>. | ||
| 2060 | /// </summary> | ||
| 2061 | /// <param name="source">Value source.</param> | ||
| 2062 | /// <param name="bitmask">Bit-mask of the bits involved.</param> | ||
| 2063 | /// <param name="value">New value.</param> | ||
| 2064 | /// <returns><see cref="byte"/> value.</returns> | ||
| 2065 | public static byte SetMaskedValue(this byte source, byte bitmask, byte value) | ||
| 2066 | { | ||
| 2067 | return ((byte)((source & ~bitmask) | value)); | ||
| 2068 | } | ||
| 2069 | |||
| 2070 | /// <summary> | ||
| 2071 | /// Returns value after setting a new <paramref name="value"/> for the bits specified by the <paramref name="bitmask"/>. | ||
| 2072 | /// </summary> | ||
| 2073 | /// <param name="source">Value source.</param> | ||
| 2074 | /// <param name="bitmask"><see cref="Bits"/> that make-up the bit-mask.</param> | ||
| 2075 | /// <param name="value">New value.</param> | ||
| 2076 | /// <returns><see cref="short"/> value.</returns> | ||
| 2077 | [CLSCompliant(false)] | ||
| 2078 | public static short SetMaskedValue(this short source, Bits bitmask, short value) | ||
| 2079 | { | ||
| 2080 | checked | ||
| 2081 | { | ||
| 2082 | return SetMaskedValue(source, (short)bitmask, value); | ||
| 2083 | } | ||
| 2084 | } | ||
| 2085 | |||
| 2086 | /// <summary> | ||
| 2087 | /// Returns value after setting a new <paramref name="value"/> for the bits specified by the <paramref name="bitmask"/>. | ||
| 2088 | /// </summary> | ||
| 2089 | /// <param name="source">Value source.</param> | ||
| 2090 | /// <param name="bitmask">Bit-mask of the bits involved.</param> | ||
| 2091 | /// <param name="value">New value.</param> | ||
| 2092 | /// <returns><see cref="short"/> value.</returns> | ||
| 2093 | public static short SetMaskedValue(this short source, short bitmask, short value) | ||
| 2094 | { | ||
| 2095 | return ((short)((short)(source & ~bitmask) | value)); | ||
| 2096 | } | ||
| 2097 | |||
| 2098 | /// <summary> | ||
| 2099 | /// Returns value after setting a new <paramref name="value"/> for the bits specified by the <paramref name="bitmask"/>. | ||
| 2100 | /// </summary> | ||
| 2101 | /// <param name="source">Value source.</param> | ||
| 2102 | /// <param name="bitmask"><see cref="Bits"/> that make-up the bit-mask.</param> | ||
| 2103 | /// <param name="value">New value.</param> | ||
| 2104 | /// <returns><see cref="ushort"/> value.</returns> | ||
| 2105 | [CLSCompliant(false)] | ||
| 2106 | public static ushort SetMaskedValue(this ushort source, Bits bitmask, ushort value) | ||
| 2107 | { | ||
| 2108 | checked | ||
| 2109 | { | ||
| 2110 | return SetMaskedValue(source, (ushort)bitmask, value); | ||
| 2111 | } | ||
| 2112 | } | ||
| 2113 | |||
| 2114 | /// <summary> | ||
| 2115 | /// Returns value after setting a new <paramref name="value"/> for the bits specified by the <paramref name="bitmask"/>. | ||
| 2116 | /// </summary> | ||
| 2117 | /// <param name="source">Value source.</param> | ||
| 2118 | /// <param name="bitmask">Bit-mask of the bits involved.</param> | ||
| 2119 | /// <param name="value">New value.</param> | ||
| 2120 | /// <returns><see cref="ushort"/> value.</returns> | ||
| 2121 | [CLSCompliant(false)] | ||
| 2122 | public static ushort SetMaskedValue(this ushort source, ushort bitmask, ushort value) | ||
| 2123 | { | ||
| 2124 | return ((ushort)((source & ~bitmask) | value)); | ||
| 2125 | } | ||
| 2126 | |||
| 2127 | /// <summary> | ||
| 2128 | /// Returns value after setting a new <paramref name="value"/> for the bits specified by the <paramref name="bitmask"/>. | ||
| 2129 | /// </summary> | ||
| 2130 | /// <param name="source">Value source.</param> | ||
| 2131 | /// <param name="bitmask"><see cref="Bits"/> that make-up the bit-mask.</param> | ||
| 2132 | /// <param name="value">New value.</param> | ||
| 2133 | /// <returns><see cref="Int24"/> value.</returns> | ||
| 2134 | [CLSCompliant(false)] | ||
| 2135 | public static Int24 SetMaskedValue(this Int24 source, Bits bitmask, Int24 value) | ||
| 2136 | { | ||
| 2137 | checked | ||
| 2138 | { | ||
| 2139 | return SetMaskedValue(source, (Int24)bitmask, value); | ||
| 2140 | } | ||
| 2141 | } | ||
| 2142 | |||
| 2143 | /// <summary> | ||
| 2144 | /// Returns value after setting a new <paramref name="value"/> for the bits specified by the <paramref name="bitmask"/>. | ||
| 2145 | /// </summary> | ||
| 2146 | /// <param name="source">Value source.</param> | ||
| 2147 | /// <param name="bitmask">Bit-mask of the bits involved.</param> | ||
| 2148 | /// <param name="value">New value.</param> | ||
| 2149 | /// <returns><see cref="Int24"/> value.</returns> | ||
| 2150 | public static Int24 SetMaskedValue(this Int24 source, Int24 bitmask, Int24 value) | ||
| 2151 | { | ||
| 2152 | return ((source & ~bitmask) | value); | ||
| 2153 | } | ||
| 2154 | |||
| 2155 | /// <summary> | ||
| 2156 | /// Returns value after setting a new <paramref name="value"/> for the bits specified by the <paramref name="bitmask"/>. | ||
| 2157 | /// </summary> | ||
| 2158 | /// <param name="source">Value source.</param> | ||
| 2159 | /// <param name="bitmask"><see cref="Bits"/> that make-up the bit-mask.</param> | ||
| 2160 | /// <param name="value">New value.</param> | ||
| 2161 | /// <returns><see cref="UInt24"/> value.</returns> | ||
| 2162 | [CLSCompliant(false)] | ||
| 2163 | public static UInt24 SetMaskedValue(this UInt24 source, Bits bitmask, UInt24 value) | ||
| 2164 | { | ||
| 2165 | checked | ||
| 2166 | { | ||
| 2167 | return SetMaskedValue(source, (UInt24)bitmask, value); | ||
| 2168 | } | ||
| 2169 | } | ||
| 2170 | |||
| 2171 | /// <summary> | ||
| 2172 | /// Returns value after setting a new <paramref name="value"/> for the bits specified by the <paramref name="bitmask"/>. | ||
| 2173 | /// </summary> | ||
| 2174 | /// <param name="source">Value source.</param> | ||
| 2175 | /// <param name="bitmask">Bit-mask of the bits involved.</param> | ||
| 2176 | /// <param name="value">New value.</param> | ||
| 2177 | /// <returns><see cref="UInt24"/> value.</returns> | ||
| 2178 | [CLSCompliant(false)] | ||
| 2179 | public static UInt24 SetMaskedValue(this UInt24 source, UInt24 bitmask, UInt24 value) | ||
| 2180 | { | ||
| 2181 | return ((source & ~bitmask) | value); | ||
| 2182 | } | ||
| 2183 | |||
| 2184 | /// <summary> | ||
| 2185 | /// Returns value after setting a new <paramref name="value"/> for the bits specified by the <paramref name="bitmask"/>. | ||
| 2186 | /// </summary> | ||
| 2187 | /// <param name="source">Value source.</param> | ||
| 2188 | /// <param name="bitmask"><see cref="Bits"/> that make-up the bit-mask.</param> | ||
| 2189 | /// <param name="value">New value.</param> | ||
| 2190 | /// <returns><see cref="int"/> value.</returns> | ||
| 2191 | [CLSCompliant(false)] | ||
| 2192 | public static int SetMaskedValue(this int source, Bits bitmask, int value) | ||
| 2193 | { | ||
| 2194 | checked | ||
| 2195 | { | ||
| 2196 | return SetMaskedValue(source, (int)bitmask, value); | ||
| 2197 | } | ||
| 2198 | } | ||
| 2199 | |||
| 2200 | /// <summary> | ||
| 2201 | /// Returns value after setting a new <paramref name="value"/> for the bits specified by the <paramref name="bitmask"/>. | ||
| 2202 | /// </summary> | ||
| 2203 | /// <param name="source">Value source.</param> | ||
| 2204 | /// <param name="bitmask">Bit-mask of the bits involved.</param> | ||
| 2205 | /// <param name="value">New value.</param> | ||
| 2206 | /// <returns><see cref="int"/> value.</returns> | ||
| 2207 | public static int SetMaskedValue(this int source, int bitmask, int value) | ||
| 2208 | { | ||
| 2209 | return ((source & ~bitmask) | value); | ||
| 2210 | } | ||
| 2211 | |||
| 2212 | /// <summary> | ||
| 2213 | /// Returns value after setting a new <paramref name="value"/> for the bits specified by the <paramref name="bitmask"/>. | ||
| 2214 | /// </summary> | ||
| 2215 | /// <param name="source">Value source.</param> | ||
| 2216 | /// <param name="bitmask"><see cref="Bits"/> that make-up the bit-mask.</param> | ||
| 2217 | /// <param name="value">New value.</param> | ||
| 2218 | /// <returns><see cref="uint"/> value.</returns> | ||
| 2219 | [CLSCompliant(false)] | ||
| 2220 | public static uint SetMaskedValue(this uint source, Bits bitmask, uint value) | ||
| 2221 | { | ||
| 2222 | checked | ||
| 2223 | { | ||
| 2224 | return SetMaskedValue(source, (uint)bitmask, value); | ||
| 2225 | } | ||
| 2226 | } | ||
| 2227 | |||
| 2228 | /// <summary> | ||
| 2229 | /// Returns value after setting a new <paramref name="value"/> for the bits specified by the <paramref name="bitmask"/>. | ||
| 2230 | /// </summary> | ||
| 2231 | /// <param name="source">Value source.</param> | ||
| 2232 | /// <param name="bitmask">Bit-mask of the bits involved.</param> | ||
| 2233 | /// <param name="value">New value.</param> | ||
| 2234 | /// <returns><see cref="uint"/> value.</returns> | ||
| 2235 | [CLSCompliant(false)] | ||
| 2236 | public static uint SetMaskedValue(this uint source, uint bitmask, uint value) | ||
| 2237 | { | ||
| 2238 | return ((source & ~bitmask) | value); | ||
| 2239 | } | ||
| 2240 | |||
| 2241 | /// <summary> | ||
| 2242 | /// Returns value after setting a new <paramref name="value"/> for the bits specified by the <paramref name="bitmask"/>. | ||
| 2243 | /// </summary> | ||
| 2244 | /// <param name="source">Value source.</param> | ||
| 2245 | /// <param name="bitmask"><see cref="Bits"/> that make-up the bit-mask.</param> | ||
| 2246 | /// <param name="value">New value.</param> | ||
| 2247 | /// <returns><see cref="long"/> value.</returns> | ||
| 2248 | [CLSCompliant(false)] | ||
| 2249 | public static long SetMaskedValue(this long source, Bits bitmask, long value) | ||
| 2250 | { | ||
| 2251 | checked | ||
| 2252 | { | ||
| 2253 | return SetMaskedValue(source, (long)bitmask, value); | ||
| 2254 | } | ||
| 2255 | } | ||
| 2256 | |||
| 2257 | /// <summary> | ||
| 2258 | /// Returns value after setting a new <paramref name="value"/> for the bits specified by the <paramref name="bitmask"/>. | ||
| 2259 | /// </summary> | ||
| 2260 | /// <param name="source">Value source.</param> | ||
| 2261 | /// <param name="bitmask">Bit-mask of the bits involved.</param> | ||
| 2262 | /// <param name="value">New value.</param> | ||
| 2263 | /// <returns><see cref="long"/> value.</returns> | ||
| 2264 | public static long SetMaskedValue(this long source, long bitmask, long value) | ||
| 2265 | { | ||
| 2266 | return ((source & ~bitmask) | value); | ||
| 2267 | } | ||
| 2268 | |||
| 2269 | /// <summary> | ||
| 2270 | /// Returns value after setting a new <paramref name="value"/> for the bits specified by the <paramref name="bitmask"/>. | ||
| 2271 | /// </summary> | ||
| 2272 | /// <param name="source">Value source.</param> | ||
| 2273 | /// <param name="bitmask"><see cref="Bits"/> that make-up the bit-mask.</param> | ||
| 2274 | /// <param name="value">New value.</param> | ||
| 2275 | /// <returns><see cref="ulong"/> value.</returns> | ||
| 2276 | [CLSCompliant(false)] | ||
| 2277 | public static ulong SetMaskedValue(this ulong source, Bits bitmask, ulong value) | ||
| 2278 | { | ||
| 2279 | checked | ||
| 2280 | { | ||
| 2281 | return SetMaskedValue(source, (ulong)bitmask, value); | ||
| 2282 | } | ||
| 2283 | } | ||
| 2284 | |||
| 2285 | /// <summary> | ||
| 2286 | /// Returns value after setting a new <paramref name="value"/> for the bits specified by the <paramref name="bitmask"/>. | ||
| 2287 | /// </summary> | ||
| 2288 | /// <param name="source">Value source.</param> | ||
| 2289 | /// <param name="bitmask">Bit-mask of the bits involved.</param> | ||
| 2290 | /// <param name="value">New value.</param> | ||
| 2291 | /// <returns><see cref="ulong"/> value.</returns> | ||
| 2292 | [CLSCompliant(false)] | ||
| 2293 | public static ulong SetMaskedValue(this ulong source, ulong bitmask, ulong value) | ||
| 2294 | { | ||
| 2295 | return ((source & ~bitmask) | value); | ||
| 2296 | } | ||
| 2297 | |||
| 2298 | #endregion | ||
| 2299 | |||
| 2300 | #region [ Bit Rotation Extensions ] | ||
| 2301 | |||
| 2302 | /// <summary> | ||
| 2303 | /// Performs rightwise bit-rotation for the specified number of rotations. | ||
| 2304 | /// </summary> | ||
| 2305 | /// <param name="value">Value used for bit-rotation.</param> | ||
| 2306 | /// <param name="rotations">Number of rotations to perform.</param> | ||
| 2307 | /// <returns>Value that has its bits rotated to the right the specified number of times.</returns> | ||
| 2308 | /// <remarks> | ||
| 2309 | /// Actual rotation direction is from a big-endian perspective - this is an artifact of the native | ||
| 2310 | /// .NET bit shift operators. As a result bits may actually appear to rotate right on little-endian | ||
| 2311 | /// architectures. | ||
| 2312 | /// </remarks> | ||
| 2313 | public static byte BitRotL(this byte value, int rotations) | ||
| 2314 | { | ||
| 2315 | bool hiBitSet; | ||
| 2316 | |||
| 2317 | for (int x = 1; x <= (rotations % 8); x++) | ||
| 2318 | { | ||
| 2319 | hiBitSet = value.CheckBits(Bits.Bit07); | ||
| 2320 | |||
| 2321 | value <<= 1; | ||
| 2322 | |||
| 2323 | if (hiBitSet) | ||
| 2324 | value = value.SetBits(Bits.Bit00); | ||
| 2325 | } | ||
| 2326 | |||
| 2327 | return value; | ||
| 2328 | } | ||
| 2329 | |||
| 2330 | /// <summary> | ||
| 2331 | /// Performs rightwise bit-rotation for the specified number of rotations. | ||
| 2332 | /// </summary> | ||
| 2333 | /// <param name="value">Value used for bit-rotation.</param> | ||
| 2334 | /// <param name="rotations">Number of rotations to perform.</param> | ||
| 2335 | /// <returns>Value that has its bits rotated to the right the specified number of times.</returns> | ||
| 2336 | /// <remarks> | ||
| 2337 | /// Actual rotation direction is from a big-endian perspective - this is an artifact of the native | ||
| 2338 | /// .NET bit shift operators. As a result bits may actually appear to rotate right on little-endian | ||
| 2339 | /// architectures. | ||
| 2340 | /// </remarks> | ||
| 2341 | [CLSCompliant(false)] | ||
| 2342 | public static sbyte BitRotL(this sbyte value, int rotations) | ||
| 2343 | { | ||
| 2344 | bool hiBitSet; | ||
| 2345 | |||
| 2346 | for (int x = 1; x <= (rotations % 8); x++) | ||
| 2347 | { | ||
| 2348 | hiBitSet = value.CheckBits(Bits.Bit07); | ||
| 2349 | |||
| 2350 | value <<= 1; | ||
| 2351 | |||
| 2352 | if (hiBitSet) | ||
| 2353 | value = value.SetBits(Bits.Bit00); | ||
| 2354 | } | ||
| 2355 | |||
| 2356 | return value; | ||
| 2357 | } | ||
| 2358 | |||
| 2359 | /// <summary> | ||
| 2360 | /// Performs rightwise bit-rotation for the specified number of rotations. | ||
| 2361 | /// </summary> | ||
| 2362 | /// <param name="value">Value used for bit-rotation.</param> | ||
| 2363 | /// <param name="rotations">Number of rotations to perform.</param> | ||
| 2364 | /// <returns>Value that has its bits rotated to the right the specified number of times.</returns> | ||
| 2365 | /// <remarks> | ||
| 2366 | /// Actual rotation direction is from a big-endian perspective - this is an artifact of the native | ||
| 2367 | /// .NET bit shift operators. As a result bits may actually appear to rotate right on little-endian | ||
| 2368 | /// architectures. | ||
| 2369 | /// </remarks> | ||
| 2370 | public static short BitRotL(this short value, int rotations) | ||
| 2371 | { | ||
| 2372 | bool hiBitSet; | ||
| 2373 | |||
| 2374 | for (int x = 1; x <= (rotations % 16); x++) | ||
| 2375 | { | ||
| 2376 | hiBitSet = value.CheckBits(Bits.Bit15); | ||
| 2377 | |||
| 2378 | value <<= 1; | ||
| 2379 | |||
| 2380 | if (hiBitSet) | ||
| 2381 | value = value.SetBits(Bits.Bit00); | ||
| 2382 | } | ||
| 2383 | |||
| 2384 | return value; | ||
| 2385 | } | ||
| 2386 | |||
| 2387 | /// <summary> | ||
| 2388 | /// Performs rightwise bit-rotation for the specified number of rotations. | ||
| 2389 | /// </summary> | ||
| 2390 | /// <param name="value">Value used for bit-rotation.</param> | ||
| 2391 | /// <param name="rotations">Number of rotations to perform.</param> | ||
| 2392 | /// <returns>Value that has its bits rotated to the right the specified number of times.</returns> | ||
| 2393 | /// <remarks> | ||
| 2394 | /// Actual rotation direction is from a big-endian perspective - this is an artifact of the native | ||
| 2395 | /// .NET bit shift operators. As a result bits may actually appear to rotate right on little-endian | ||
| 2396 | /// architectures. | ||
| 2397 | /// </remarks> | ||
| 2398 | [CLSCompliant(false)] | ||
| 2399 | public static ushort BitRotL(this ushort value, int rotations) | ||
| 2400 | { | ||
| 2401 | bool hiBitSet; | ||
| 2402 | |||
| 2403 | for (int x = 1; x <= (rotations % 16); x++) | ||
| 2404 | { | ||
| 2405 | hiBitSet = value.CheckBits(Bits.Bit15); | ||
| 2406 | |||
| 2407 | value <<= 1; | ||
| 2408 | |||
| 2409 | if (hiBitSet) | ||
| 2410 | value = value.SetBits(Bits.Bit00); | ||
| 2411 | } | ||
| 2412 | |||
| 2413 | return value; | ||
| 2414 | } | ||
| 2415 | |||
| 2416 | /// <summary> | ||
| 2417 | /// Performs rightwise bit-rotation for the specified number of rotations. | ||
| 2418 | /// </summary> | ||
| 2419 | /// <param name="value">Value used for bit-rotation.</param> | ||
| 2420 | /// <param name="rotations">Number of rotations to perform.</param> | ||
| 2421 | /// <returns>Value that has its bits rotated to the right the specified number of times.</returns> | ||
| 2422 | /// <remarks> | ||
| 2423 | /// Actual rotation direction is from a big-endian perspective - this is an artifact of the native | ||
| 2424 | /// .NET bit shift operators. As a result bits may actually appear to rotate right on little-endian | ||
| 2425 | /// architectures. | ||
| 2426 | /// </remarks> | ||
| 2427 | public static Int24 BitRotL(this Int24 value, int rotations) | ||
| 2428 | { | ||
| 2429 | bool hiBitSet; | ||
| 2430 | |||
| 2431 | for (int x = 1; x <= (rotations % 24); x++) | ||
| 2432 | { | ||
| 2433 | hiBitSet = value.CheckBits(Bits.Bit23); | ||
| 2434 | |||
| 2435 | value <<= 1; | ||
| 2436 | |||
| 2437 | if (hiBitSet) | ||
| 2438 | value = value.SetBits(Bits.Bit00); | ||
| 2439 | } | ||
| 2440 | |||
| 2441 | return value; | ||
| 2442 | } | ||
| 2443 | |||
| 2444 | /// <summary> | ||
| 2445 | /// Performs rightwise bit-rotation for the specified number of rotations. | ||
| 2446 | /// </summary> | ||
| 2447 | /// <param name="value">Value used for bit-rotation.</param> | ||
| 2448 | /// <param name="rotations">Number of rotations to perform.</param> | ||
| 2449 | /// <returns>Value that has its bits rotated to the right the specified number of times.</returns> | ||
| 2450 | /// <remarks> | ||
| 2451 | /// Actual rotation direction is from a big-endian perspective - this is an artifact of the native | ||
| 2452 | /// .NET bit shift operators. As a result bits may actually appear to rotate right on little-endian | ||
| 2453 | /// architectures. | ||
| 2454 | /// </remarks> | ||
| 2455 | [CLSCompliant(false)] | ||
| 2456 | public static UInt24 BitRotL(this UInt24 value, int rotations) | ||
| 2457 | { | ||
| 2458 | bool hiBitSet; | ||
| 2459 | |||
| 2460 | for (int x = 1; x <= (rotations % 24); x++) | ||
| 2461 | { | ||
| 2462 | hiBitSet = value.CheckBits(Bits.Bit23); | ||
| 2463 | |||
| 2464 | value <<= 1; | ||
| 2465 | |||
| 2466 | if (hiBitSet) | ||
| 2467 | value = value.SetBits(Bits.Bit00); | ||
| 2468 | } | ||
| 2469 | |||
| 2470 | return value; | ||
| 2471 | } | ||
| 2472 | |||
| 2473 | /// <summary> | ||
| 2474 | /// Performs rightwise bit-rotation for the specified number of rotations. | ||
| 2475 | /// </summary> | ||
| 2476 | /// <param name="value">Value used for bit-rotation.</param> | ||
| 2477 | /// <param name="rotations">Number of rotations to perform.</param> | ||
| 2478 | /// <returns>Value that has its bits rotated to the right the specified number of times.</returns> | ||
| 2479 | /// <remarks> | ||
| 2480 | /// Actual rotation direction is from a big-endian perspective - this is an artifact of the native | ||
| 2481 | /// .NET bit shift operators. As a result bits may actually appear to rotate right on little-endian | ||
| 2482 | /// architectures. | ||
| 2483 | /// </remarks> | ||
| 2484 | public static int BitRotL(this int value, int rotations) | ||
| 2485 | { | ||
| 2486 | bool hiBitSet; | ||
| 2487 | |||
| 2488 | for (int x = 1; x <= (rotations % 32); x++) | ||
| 2489 | { | ||
| 2490 | hiBitSet = value.CheckBits(Bits.Bit31); | ||
| 2491 | |||
| 2492 | value <<= 1; | ||
| 2493 | |||
| 2494 | if (hiBitSet) | ||
| 2495 | value = value.SetBits(Bits.Bit00); | ||
| 2496 | } | ||
| 2497 | |||
| 2498 | return value; | ||
| 2499 | } | ||
| 2500 | |||
| 2501 | /// <summary> | ||
| 2502 | /// Performs rightwise bit-rotation for the specified number of rotations. | ||
| 2503 | /// </summary> | ||
| 2504 | /// <param name="value">Value used for bit-rotation.</param> | ||
| 2505 | /// <param name="rotations">Number of rotations to perform.</param> | ||
| 2506 | /// <returns>Value that has its bits rotated to the right the specified number of times.</returns> | ||
| 2507 | /// <remarks> | ||
| 2508 | /// Actual rotation direction is from a big-endian perspective - this is an artifact of the native | ||
| 2509 | /// .NET bit shift operators. As a result bits may actually appear to rotate right on little-endian | ||
| 2510 | /// architectures. | ||
| 2511 | /// </remarks> | ||
| 2512 | [CLSCompliant(false)] | ||
| 2513 | public static uint BitRotL(this uint value, int rotations) | ||
| 2514 | { | ||
| 2515 | bool hiBitSet; | ||
| 2516 | |||
| 2517 | for (int x = 1; x <= (rotations % 32); x++) | ||
| 2518 | { | ||
| 2519 | hiBitSet = value.CheckBits(Bits.Bit31); | ||
| 2520 | |||
| 2521 | value <<= 1; | ||
| 2522 | |||
| 2523 | if (hiBitSet) | ||
| 2524 | value = value.SetBits(Bits.Bit00); | ||
| 2525 | } | ||
| 2526 | |||
| 2527 | return value; | ||
| 2528 | } | ||
| 2529 | |||
| 2530 | /// <summary> | ||
| 2531 | /// Performs rightwise bit-rotation for the specified number of rotations. | ||
| 2532 | /// </summary> | ||
| 2533 | /// <param name="value">Value used for bit-rotation.</param> | ||
| 2534 | /// <param name="rotations">Number of rotations to perform.</param> | ||
| 2535 | /// <returns>Value that has its bits rotated to the right the specified number of times.</returns> | ||
| 2536 | /// <remarks> | ||
| 2537 | /// Actual rotation direction is from a big-endian perspective - this is an artifact of the native | ||
| 2538 | /// .NET bit shift operators. As a result bits may actually appear to rotate right on little-endian | ||
| 2539 | /// architectures. | ||
| 2540 | /// </remarks> | ||
| 2541 | public static long BitRotL(this long value, int rotations) | ||
| 2542 | { | ||
| 2543 | bool hiBitSet; | ||
| 2544 | |||
| 2545 | for (int x = 1; x <= (rotations % 64); x++) | ||
| 2546 | { | ||
| 2547 | hiBitSet = value.CheckBits(Bits.Bit63); | ||
| 2548 | |||
| 2549 | value <<= 1; | ||
| 2550 | |||
| 2551 | if (hiBitSet) | ||
| 2552 | value = value.SetBits(Bits.Bit00); | ||
| 2553 | } | ||
| 2554 | |||
| 2555 | return value; | ||
| 2556 | } | ||
| 2557 | |||
| 2558 | /// <summary> | ||
| 2559 | /// Performs rightwise bit-rotation for the specified number of rotations. | ||
| 2560 | /// </summary> | ||
| 2561 | /// <param name="value">Value used for bit-rotation.</param> | ||
| 2562 | /// <param name="rotations">Number of rotations to perform.</param> | ||
| 2563 | /// <returns>Value that has its bits rotated to the right the specified number of times.</returns> | ||
| 2564 | /// <remarks> | ||
| 2565 | /// Actual rotation direction is from a big-endian perspective - this is an artifact of the native | ||
| 2566 | /// .NET bit shift operators. As a result bits may actually appear to rotate right on little-endian | ||
| 2567 | /// architectures. | ||
| 2568 | /// </remarks> | ||
| 2569 | [CLSCompliant(false)] | ||
| 2570 | public static ulong BitRotL(this ulong value, int rotations) | ||
| 2571 | { | ||
| 2572 | bool hiBitSet; | ||
| 2573 | |||
| 2574 | for (int x = 1; x <= (rotations % 64); x++) | ||
| 2575 | { | ||
| 2576 | hiBitSet = value.CheckBits(Bits.Bit63); | ||
| 2577 | |||
| 2578 | value <<= 1; | ||
| 2579 | |||
| 2580 | if (hiBitSet) | ||
| 2581 | value = value.SetBits(Bits.Bit00); | ||
| 2582 | } | ||
| 2583 | |||
| 2584 | return value; | ||
| 2585 | } | ||
| 2586 | |||
| 2587 | /// <summary> | ||
| 2588 | /// Performs rightwise bit-rotation for the specified number of rotations. | ||
| 2589 | /// </summary> | ||
| 2590 | /// <param name="value">Value used for bit-rotation.</param> | ||
| 2591 | /// <param name="rotations">Number of rotations to perform.</param> | ||
| 2592 | /// <returns>Value that has its bits rotated to the right the specified number of times.</returns> | ||
| 2593 | /// <remarks> | ||
| 2594 | /// Actual rotation direction is from a big-endian perspective - this is an artifact of the native | ||
| 2595 | /// .NET bit shift operators. As a result bits may actually appear to rotate left on little-endian | ||
| 2596 | /// architectures. | ||
| 2597 | /// </remarks> | ||
| 2598 | public static byte BitRotR(this byte value, int rotations) | ||
| 2599 | { | ||
| 2600 | bool loBitSet; | ||
| 2601 | |||
| 2602 | for (int x = 1; x <= (rotations % 8); x++) | ||
| 2603 | { | ||
| 2604 | loBitSet = value.CheckBits(Bits.Bit00); | ||
| 2605 | |||
| 2606 | value >>= 1; | ||
| 2607 | |||
| 2608 | if (loBitSet) | ||
| 2609 | value = value.SetBits(Bits.Bit07); | ||
| 2610 | else | ||
| 2611 | value = value.ClearBits(Bits.Bit07); | ||
| 2612 | } | ||
| 2613 | |||
| 2614 | return value; | ||
| 2615 | } | ||
| 2616 | |||
| 2617 | /// <summary> | ||
| 2618 | /// Performs rightwise bit-rotation for the specified number of rotations. | ||
| 2619 | /// </summary> | ||
| 2620 | /// <param name="value">Value used for bit-rotation.</param> | ||
| 2621 | /// <param name="rotations">Number of rotations to perform.</param> | ||
| 2622 | /// <returns>Value that has its bits rotated to the right the specified number of times.</returns> | ||
| 2623 | /// <remarks> | ||
| 2624 | /// Actual rotation direction is from a big-endian perspective - this is an artifact of the native | ||
| 2625 | /// .NET bit shift operators. As a result bits may actually appear to rotate left on little-endian | ||
| 2626 | /// architectures. | ||
| 2627 | /// </remarks> | ||
| 2628 | [CLSCompliant(false)] | ||
| 2629 | public static sbyte BitRotR(this sbyte value, int rotations) | ||
| 2630 | { | ||
| 2631 | bool loBitSet; | ||
| 2632 | |||
| 2633 | for (int x = 1; x <= (rotations % 8); x++) | ||
| 2634 | { | ||
| 2635 | loBitSet = value.CheckBits(Bits.Bit00); | ||
| 2636 | |||
| 2637 | value >>= 1; | ||
| 2638 | |||
| 2639 | if (loBitSet) | ||
| 2640 | value = value.SetBits(Bits.Bit07); | ||
| 2641 | else | ||
| 2642 | value = value.ClearBits(Bits.Bit07); | ||
| 2643 | } | ||
| 2644 | |||
| 2645 | return value; | ||
| 2646 | } | ||
| 2647 | |||
| 2648 | /// <summary> | ||
| 2649 | /// Performs rightwise bit-rotation for the specified number of rotations. | ||
| 2650 | /// </summary> | ||
| 2651 | /// <param name="value">Value used for bit-rotation.</param> | ||
| 2652 | /// <param name="rotations">Number of rotations to perform.</param> | ||
| 2653 | /// <returns>Value that has its bits rotated to the right the specified number of times.</returns> | ||
| 2654 | /// <remarks> | ||
| 2655 | /// Actual rotation direction is from a big-endian perspective - this is an artifact of the native | ||
| 2656 | /// .NET bit shift operators. As a result bits may actually appear to rotate left on little-endian | ||
| 2657 | /// architectures. | ||
| 2658 | /// </remarks> | ||
| 2659 | public static short BitRotR(this short value, int rotations) | ||
| 2660 | { | ||
| 2661 | bool loBitSet; | ||
| 2662 | |||
| 2663 | for (int x = 1; x <= (rotations % 16); x++) | ||
| 2664 | { | ||
| 2665 | loBitSet = value.CheckBits(Bits.Bit00); | ||
| 2666 | |||
| 2667 | value >>= 1; | ||
| 2668 | |||
| 2669 | if (loBitSet) | ||
| 2670 | value = value.SetBits(Bits.Bit15); | ||
| 2671 | else | ||
| 2672 | value = value.ClearBits(Bits.Bit15); | ||
| 2673 | } | ||
| 2674 | |||
| 2675 | return value; | ||
| 2676 | } | ||
| 2677 | |||
| 2678 | /// <summary> | ||
| 2679 | /// Performs rightwise bit-rotation for the specified number of rotations. | ||
| 2680 | /// </summary> | ||
| 2681 | /// <param name="value">Value used for bit-rotation.</param> | ||
| 2682 | /// <param name="rotations">Number of rotations to perform.</param> | ||
| 2683 | /// <returns>Value that has its bits rotated to the right the specified number of times.</returns> | ||
| 2684 | /// <remarks> | ||
| 2685 | /// Actual rotation direction is from a big-endian perspective - this is an artifact of the native | ||
| 2686 | /// .NET bit shift operators. As a result bits may actually appear to rotate left on little-endian | ||
| 2687 | /// architectures. | ||
| 2688 | /// </remarks> | ||
| 2689 | [CLSCompliant(false)] | ||
| 2690 | public static ushort BitRotR(this ushort value, int rotations) | ||
| 2691 | { | ||
| 2692 | bool loBitSet; | ||
| 2693 | |||
| 2694 | for (int x = 1; x <= (rotations % 16); x++) | ||
| 2695 | { | ||
| 2696 | loBitSet = value.CheckBits(Bits.Bit00); | ||
| 2697 | |||
| 2698 | value >>= 1; | ||
| 2699 | |||
| 2700 | if (loBitSet) | ||
| 2701 | value = value.SetBits(Bits.Bit15); | ||
| 2702 | else | ||
| 2703 | value = value.ClearBits(Bits.Bit15); | ||
| 2704 | } | ||
| 2705 | |||
| 2706 | return value; | ||
| 2707 | } | ||
| 2708 | |||
| 2709 | /// <summary> | ||
| 2710 | /// Performs rightwise bit-rotation for the specified number of rotations. | ||
| 2711 | /// </summary> | ||
| 2712 | /// <param name="value">Value used for bit-rotation.</param> | ||
| 2713 | /// <param name="rotations">Number of rotations to perform.</param> | ||
| 2714 | /// <returns>Value that has its bits rotated to the right the specified number of times.</returns> | ||
| 2715 | /// <remarks> | ||
| 2716 | /// Actual rotation direction is from a big-endian perspective - this is an artifact of the native | ||
| 2717 | /// .NET bit shift operators. As a result bits may actually appear to rotate left on little-endian | ||
| 2718 | /// architectures. | ||
| 2719 | /// </remarks> | ||
| 2720 | public static Int24 BitRotR(this Int24 value, int rotations) | ||
| 2721 | { | ||
| 2722 | bool loBitSet; | ||
| 2723 | |||
| 2724 | for (int x = 1; x <= (rotations % 24); x++) | ||
| 2725 | { | ||
| 2726 | loBitSet = value.CheckBits(Bits.Bit00); | ||
| 2727 | |||
| 2728 | value >>= 1; | ||
| 2729 | |||
| 2730 | if (loBitSet) | ||
| 2731 | value = value.SetBits(Bits.Bit23); | ||
| 2732 | else | ||
| 2733 | value = value.ClearBits(Bits.Bit23); | ||
| 2734 | } | ||
| 2735 | |||
| 2736 | return value; | ||
| 2737 | } | ||
| 2738 | |||
| 2739 | /// <summary> | ||
| 2740 | /// Performs rightwise bit-rotation for the specified number of rotations. | ||
| 2741 | /// </summary> | ||
| 2742 | /// <param name="value">Value used for bit-rotation.</param> | ||
| 2743 | /// <param name="rotations">Number of rotations to perform.</param> | ||
| 2744 | /// <returns>Value that has its bits rotated to the right the specified number of times.</returns> | ||
| 2745 | /// <remarks> | ||
| 2746 | /// Actual rotation direction is from a big-endian perspective - this is an artifact of the native | ||
| 2747 | /// .NET bit shift operators. As a result bits may actually appear to rotate left on little-endian | ||
| 2748 | /// architectures. | ||
| 2749 | /// </remarks> | ||
| 2750 | [CLSCompliant(false)] | ||
| 2751 | public static UInt24 BitRotR(this UInt24 value, int rotations) | ||
| 2752 | { | ||
| 2753 | bool loBitSet; | ||
| 2754 | |||
| 2755 | for (int x = 1; x <= (rotations % 24); x++) | ||
| 2756 | { | ||
| 2757 | loBitSet = value.CheckBits(Bits.Bit00); | ||
| 2758 | |||
| 2759 | value >>= 1; | ||
| 2760 | |||
| 2761 | if (loBitSet) | ||
| 2762 | value = value.SetBits(Bits.Bit23); | ||
| 2763 | else | ||
| 2764 | value = value.ClearBits(Bits.Bit23); | ||
| 2765 | } | ||
| 2766 | |||
| 2767 | return value; | ||
| 2768 | } | ||
| 2769 | |||
| 2770 | /// <summary> | ||
| 2771 | /// Performs rightwise bit-rotation for the specified number of rotations. | ||
| 2772 | /// </summary> | ||
| 2773 | /// <param name="value">Value used for bit-rotation.</param> | ||
| 2774 | /// <param name="rotations">Number of rotations to perform.</param> | ||
| 2775 | /// <returns>Value that has its bits rotated to the right the specified number of times.</returns> | ||
| 2776 | /// <remarks> | ||
| 2777 | /// Actual rotation direction is from a big-endian perspective - this is an artifact of the native | ||
| 2778 | /// .NET bit shift operators. As a result bits may actually appear to rotate left on little-endian | ||
| 2779 | /// architectures. | ||
| 2780 | /// </remarks> | ||
| 2781 | public static int BitRotR(this int value, int rotations) | ||
| 2782 | { | ||
| 2783 | bool loBitSet; | ||
| 2784 | |||
| 2785 | for (int x = 1; x <= (rotations % 32); x++) | ||
| 2786 | { | ||
| 2787 | loBitSet = value.CheckBits(Bits.Bit00); | ||
| 2788 | |||
| 2789 | value >>= 1; | ||
| 2790 | |||
| 2791 | if (loBitSet) | ||
| 2792 | value = value.SetBits(Bits.Bit31); | ||
| 2793 | else | ||
| 2794 | value = value.ClearBits(Bits.Bit31); | ||
| 2795 | } | ||
| 2796 | |||
| 2797 | return value; | ||
| 2798 | } | ||
| 2799 | |||
| 2800 | /// <summary> | ||
| 2801 | /// Performs rightwise bit-rotation for the specified number of rotations. | ||
| 2802 | /// </summary> | ||
| 2803 | /// <param name="value">Value used for bit-rotation.</param> | ||
| 2804 | /// <param name="rotations">Number of rotations to perform.</param> | ||
| 2805 | /// <returns>Value that has its bits rotated to the right the specified number of times.</returns> | ||
| 2806 | /// <remarks> | ||
| 2807 | /// Actual rotation direction is from a big-endian perspective - this is an artifact of the native | ||
| 2808 | /// .NET bit shift operators. As a result bits may actually appear to rotate left on little-endian | ||
| 2809 | /// architectures. | ||
| 2810 | /// </remarks> | ||
| 2811 | [CLSCompliant(false)] | ||
| 2812 | public static uint BitRotR(this uint value, int rotations) | ||
| 2813 | { | ||
| 2814 | bool loBitSet; | ||
| 2815 | |||
| 2816 | for (int x = 1; x <= (rotations % 32); x++) | ||
| 2817 | { | ||
| 2818 | loBitSet = value.CheckBits(Bits.Bit00); | ||
| 2819 | |||
| 2820 | value >>= 1; | ||
| 2821 | |||
| 2822 | if (loBitSet) | ||
| 2823 | value = value.SetBits(Bits.Bit31); | ||
| 2824 | else | ||
| 2825 | value = value.ClearBits(Bits.Bit31); | ||
| 2826 | } | ||
| 2827 | |||
| 2828 | return value; | ||
| 2829 | } | ||
| 2830 | |||
| 2831 | /// <summary> | ||
| 2832 | /// Performs rightwise bit-rotation for the specified number of rotations. | ||
| 2833 | /// </summary> | ||
| 2834 | /// <param name="value">Value used for bit-rotation.</param> | ||
| 2835 | /// <param name="rotations">Number of rotations to perform.</param> | ||
| 2836 | /// <returns>Value that has its bits rotated to the right the specified number of times.</returns> | ||
| 2837 | /// <remarks> | ||
| 2838 | /// Actual rotation direction is from a big-endian perspective - this is an artifact of the native | ||
| 2839 | /// .NET bit shift operators. As a result bits may actually appear to rotate left on little-endian | ||
| 2840 | /// architectures. | ||
| 2841 | /// </remarks> | ||
| 2842 | public static long BitRotR(this long value, int rotations) | ||
| 2843 | { | ||
| 2844 | bool loBitSet; | ||
| 2845 | |||
| 2846 | for (int x = 1; x <= (rotations % 64); x++) | ||
| 2847 | { | ||
| 2848 | loBitSet = value.CheckBits(Bits.Bit00); | ||
| 2849 | |||
| 2850 | value >>= 1; | ||
| 2851 | |||
| 2852 | if (loBitSet) | ||
| 2853 | value = value.SetBits(Bits.Bit63); | ||
| 2854 | else | ||
| 2855 | value = value.ClearBits(Bits.Bit63); | ||
| 2856 | } | ||
| 2857 | |||
| 2858 | return value; | ||
| 2859 | } | ||
| 2860 | |||
| 2861 | /// <summary> | ||
| 2862 | /// Performs rightwise bit-rotation for the specified number of rotations. | ||
| 2863 | /// </summary> | ||
| 2864 | /// <param name="value">Value used for bit-rotation.</param> | ||
| 2865 | /// <param name="rotations">Number of rotations to perform.</param> | ||
| 2866 | /// <returns>Value that has its bits rotated to the right the specified number of times.</returns> | ||
| 2867 | /// <remarks> | ||
| 2868 | /// Actual rotation direction is from a big-endian perspective - this is an artifact of the native | ||
| 2869 | /// .NET bit shift operators. As a result bits may actually appear to rotate left on little-endian | ||
| 2870 | /// architectures. | ||
| 2871 | /// </remarks> | ||
| 2872 | [CLSCompliant(false)] | ||
| 2873 | public static ulong BitRotR(this ulong value, int rotations) | ||
| 2874 | { | ||
| 2875 | bool loBitSet; | ||
| 2876 | |||
| 2877 | for (int x = 1; x <= (rotations % 64); x++) | ||
| 2878 | { | ||
| 2879 | loBitSet = value.CheckBits(Bits.Bit00); | ||
| 2880 | |||
| 2881 | value >>= 1; | ||
| 2882 | |||
| 2883 | if (loBitSet) | ||
| 2884 | value = value.SetBits(Bits.Bit63); | ||
| 2885 | else | ||
| 2886 | value = value.ClearBits(Bits.Bit63); | ||
| 2887 | } | ||
| 2888 | |||
| 2889 | return value; | ||
| 2890 | } | ||
| 2891 | |||
| 2892 | #endregion | ||
| 2893 | } | ||
| 2894 | } | ||