Knowledge

Mask (computing)

Source 📝

509: 36: 1180:, often a function is used that has a large domain. To create an index from the output of the function, a modulo can be taken to reduce the size of the domain to match the size of the array; however, it is often faster on many processors to restrict the size of the hash table to powers of two sizes and use a bitmask instead. 830:
The advantage to this approach is that function argument overhead is decreased. Since the minimum datum size is one byte, separating the options into separate arguments would be wasting seven bits per argument and would occupy more stack space. Instead, functions typically accept one or more 32-bit
863:
Masks are used with IP addresses in IP ACLs (Access Control Lists) to specify what should be permitted and denied. To configure IP addresses on interfaces, masks start with 255 and have the large values on the left side: for example, IP address
1118:, in which the correspondent image areas are given a pixel value of all bits set to 0s and the surrounding areas a value of all bits set to 1s. In the sample at right, black pixels have the all-zero bits and white pixels have the all-one bits. 405:
So far the article has covered how to turn bits on and turn bits off, but not both at once. Sometimes it does not really matter what the value is, but it must be made the opposite of what it currently is. This can be achieved using the
1140: 363:, then the bit was off, but if the value is any other value, then the bit was on. What makes this convenient is that it is not necessary to figure out what the value actually is, just that it is not 1136:
operation. This way, the image pixels are appropriately placed while keeping the background surrounding pixels preserved. The result is a perfect compound of the image over the background.
936:) must match the given binary network address exactly (11000000.00000000.00000010). The last set of numbers is made of "don't cares" (.11111111). Therefore, all traffic that begins with " 1102:, when a given image is intended to be placed over a background, the transparent areas can be specified through a binary mask. This way, for each intended image there are actually two 1085: 1129:
operation. This preserves the background pixels of the transparent areas while resets with zeros the bits of the pixels which will be obscured by the overlapped image.
512:
A party trick to guess a number from which cards it is printed on uses the bits of the binary representation of the number. In the SVG file, click a card to toggle it.
351:
It is possible to use bitmasks to easily check the state of individual bits regardless of the other bits. To do this, turning off all the other bits using the bitwise
1157:, and for video titling and other image mixing applications. A faster method is to simply overwrite the background pixels with the foreground pixels if their alpha=1 892:. When the value of the mask is broken down into binary (0s and 1s), the results determine which address bits are to be considered in processing the traffic. A 1125:, to put the image on the screen over the background, the program first masks the screen pixel's bits with the image mask at the desired coordinates using the 172:, where the bitmask is used to select which element operations in the vector are to be executed (mask bit is enabled) and which are not (mask bit is clear). 855:
an alternative would be to create a class to encapsulate the set of arguments that glClear could accept and could be cleanly encapsulated in a library.
164:, etc. can be set either on or off, or inverted from on to off (or vice versa) in a single bitwise operation. An additional use of masking involves 46: 1146:
This technique is used for painting pointing device cursors, in typical 2-D videogames for characters, bullets and so on (the
104: 76: 165: 1161: 1122: 525:, bit fields are a useful way to pass a set of named boolean arguments to a function. For example, in the graphics API 83: 979:
in order to determine the ACL inverse mask. In this example, the inverse mask is determined for network address
831:
integers, with up to 32 option bits in each. While elegant, in the simplest implementation this solution is not
90: 533:
which clears the screen or other buffers. It can clear up to four buffers (the color, depth, accumulation, and
61: 1132:
Then, the program renders the image pixel's bits by combining them with the background pixel's bits using the
196: 161: 72: 497:
To write arbitrary 1s and 0s to a subset of bits, first write 0s to that subset, then set the high bits:
1549: 1147: 1091: 508: 1518: 537:), so the API authors could have had it take four arguments. But then a call to it would look like 126: 17: 944:" matches, since the last octet is "don't care". Therefore, with this mask, network addresses 97: 1468: 57: 8: 1133: 189: 1139: 1483: 1099: 933: 169: 145: 1478: 1154: 133: 1088: 1493: 534: 421: 317:(bits 4, 5, 6, 7) while leaving the lower nibble (bits 0, 1, 2, 3) unchanged. 234:(bits 4, 5, 6, 7) while leaving the lower nibble (bits 0, 1, 2, 3) unchanged. 1168:
are techniques which do not involve the image pixel mixage by binary masking.
1543: 1463: 1165: 1079: 900:-bit in the mask is a "don't care". This table further explains the concept. 889: 572:// This is not how glClear actually works and would make for unstable code. 522: 476:
masking is bit-safe, meaning that it will not affect unmasked bits because
407: 577:
which is not very descriptive. Instead there are four defined field bits,
53: 1126: 832: 896:-bit indicates that the address bit must be considered (exact match); a 1177: 425: 1473: 149: 932:
Based on the binary mask, it can be seen that the first three sets (
35: 1075: 651:
to extract the individual bits. For example, an implementation of
647:
Internally, a function taking a bitfield like this can use binary
1488: 1103: 526: 314: 295:. To leave the other bits as they were originally, they can be 231: 157: 926:
network address (binary): 11000000.00000000.00000010.00000000
1498: 1107: 852: 1160:
Although related (due to being used for the same purposes),
1106:: the actual image, in which the unused areas are given a 1084: 880:
mask. Masks for IP ACLs are the reverse: for example, mask
153: 355:
is done as discussed above and the value is compared with
1151: 1111: 448:. Therefore inversion of the values of bits is done by 125:"Signal masking" redirects here. For other uses, see 843:, so the compiler would allow a meaningless call to 929:mask (binary): 00000000.00000000.00000000.11111111 906:network address (traffic that is to be processed): 1541: 888:. This is sometimes called an inverse mask or a 346: 500:register = (register & ~bitmask) | value; 1305:// Handle memory allocation for token_array… 1183:An example of both modulo and masking in C: 622:Then a call to the function looks like this 370:Example: Querying the status of the 4th bit 62:introducing citations to additional sources 432:. Therefore, if two corresponding bits are 175: 291:ed with a 0, the result is always 0, i.e. 516: 271:More often in practice, bits are "masked 1083: 507: 52:Relevant discussion may be found on the 207:. Therefore, to make sure a bit is on, 14: 1542: 400: 1440:// Free the memory from token_array … 263: 180: 29: 1176:To create a hashing function for a 503: 152:. Using a mask, multiple bits in a 24: 1138: 25: 1561: 521:In programming languages such as 195:operation can be used, following 858: 45:relies largely or entirely on a 34: 27:Data used for bitwise operations 1317:"some hashable value" 1511: 1171: 1069: 1027:The source/source-wildcard of 971:Subtract the normal mask from 13: 1: 1504: 1114:set to 0s, and an additional 783:// Clear accumulation buffer. 487:Example: Toggling bit values 440:, but if only one of them is 188:To turn certain bits on, the 347:Querying the status of a bit 215:. To leave a bit unchanged, 7: 1457: 839:is simply defined to be an 10: 1566: 1073: 464:. If the original bit was 456:. If the original bit was 124: 144:is data that is used for 1519:"Mask R-CNN with OpenCV" 1185: 1094:(left) and masks (right) 819:// Clear stencil buffer. 657: 624: 599: 539: 490:10011101 10010101 XOR 176:Common bitmask functions 127:Masking (disambiguation) 1044:The source/wildcard of 436:, the result will be a 1143: 1095: 987:with a normal mask of 747:// Clear depth buffer. 711:// Clear color buffer. 529:, there is a command, 517:Arguments to functions 513: 494:= 10010010 01101010 1142: 1087: 1058:is the same as "host 801:GL_STENCIL_BUFFER_BIT 591:GL_STENCIL_BUFFER_BIT 511: 444:, the result will be 73:"Mask" computing 1469:Binary-coded decimal 359:. If it is equal to 148:, particularly in a 58:improve this article 765:GL_ACCUM_BUFFER_BIT 729:GL_DEPTH_BUFFER_BIT 693:GL_COLOR_BUFFER_BIT 639:GL_DEPTH_BUFFER_BIT 633:GL_COLOR_BUFFER_BIT 587:GL_ACCUM_BUFFER_BIT 583:GL_DEPTH_BUFFER_BIT 579:GL_COLOR_BUFFER_BIT 492:00001111 11111111 401:Toggling bit values 211:can be used with a 1162:transparent colors 1144: 1096: 849:glClear(GL_POINTS) 514: 146:bitwise operations 1550:Binary arithmetic 1484:Bitwise operation 1100:computer graphics 968:) are processed. 655:might look like: 472:. Also note that 309:Example: Masking 287:). When a bit is 226:Example: Masking 170:vector processing 123: 122: 108: 16:(Redirected from 1557: 1534: 1533: 1531: 1530: 1515: 1479:Bit manipulation 1453: 1450: 1447: 1444: 1441: 1438: 1435: 1432: 1429: 1426: 1423: 1420: 1417: 1414: 1411: 1408: 1405: 1402: 1399: 1396: 1393: 1390: 1389:// Using bitmask 1387: 1384: 1381: 1378: 1375: 1372: 1369: 1366: 1363: 1360: 1357: 1354: 1351: 1348: 1345: 1342: 1339: 1336: 1333: 1330: 1327: 1324: 1321: 1318: 1315: 1312: 1309: 1306: 1303: 1300: 1297: 1294: 1291: 1288: 1285: 1282: 1279: 1276: 1273: 1270: 1267: 1264: 1261: 1258: 1255: 1252: 1249: 1246: 1243: 1240: 1237: 1234: 1231: 1228: 1225: 1222: 1219: 1216: 1213: 1210: 1207: 1204: 1201: 1198: 1197:<string.h> 1195: 1192: 1191:<stdint.h> 1189: 1064: 1063: 1056: 1055: 1052: 1049: 1039: 1038: 1035: 1032: 1024:ACL equivalents 1019: 1018: 1013:(normal mask) = 1011: 1010: 1003: 1002: 993: 992: 985: 984: 977: 976: 966: 965: 958: 957: 950: 949: 942: 941: 922: 921: 912: 911: 886: 885: 878: 877: 870: 869: 850: 846: 842: 838: 826: 823: 820: 817: 814: 811: 808: 805: 802: 799: 796: 793: 790: 787: 784: 781: 778: 775: 772: 769: 766: 763: 760: 757: 754: 751: 748: 745: 742: 739: 736: 733: 730: 727: 724: 721: 718: 715: 712: 709: 706: 703: 700: 697: 694: 691: 688: 685: 682: 679: 676: 673: 670: 667: 664: 661: 654: 650: 643: 640: 637: 634: 631: 628: 618: 615: 612: 609: 606: 603: 596: 592: 588: 584: 580: 573: 570: 567: 564: 561: 558: 555: 552: 549: 546: 543: 532: 504:Uses of bitmasks 483: 479: 475: 471: 467: 463: 459: 455: 452:ing them with a 451: 447: 443: 439: 435: 431: 420: 416: 410: 366: 362: 358: 354: 306: 302: 298: 294: 290: 286: 283:" (or masked to 278: 275:" (or masked to 267: 264:Masking bits to 222: 218: 214: 210: 206: 202: 193: 184: 181:Masking bits to 134:computer science 118: 115: 109: 107: 66: 38: 30: 21: 1565: 1564: 1560: 1559: 1558: 1556: 1555: 1554: 1540: 1539: 1538: 1537: 1528: 1526: 1517: 1516: 1512: 1507: 1460: 1455: 1454: 1451: 1448: 1445: 1442: 1439: 1436: 1433: 1430: 1427: 1424: 1421: 1418: 1415: 1412: 1409: 1406: 1403: 1400: 1397: 1394: 1391: 1388: 1385: 1382: 1379: 1376: 1373: 1370: 1367: 1364: 1362:// Using modulo 1361: 1358: 1355: 1352: 1349: 1346: 1343: 1340: 1337: 1334: 1331: 1328: 1325: 1322: 1319: 1316: 1313: 1310: 1307: 1304: 1301: 1298: 1295: 1292: 1289: 1286: 1283: 1280: 1277: 1274: 1271: 1268: 1265: 1262: 1259: 1256: 1253: 1250: 1247: 1244: 1241: 1238: 1235: 1232: 1229: 1226: 1223: 1220: 1217: 1214: 1211: 1208: 1205: 1202: 1199: 1196: 1193: 1190: 1187: 1174: 1110:value with all 1082: 1072: 1061: 1060: 1053: 1050: 1047: 1046: 1037:255.255.255.255 1036: 1033: 1030: 1029: 1021:(inverse mask) 1016: 1015: 1008: 1007: 1001:255.255.255.255 1000: 999: 990: 989: 982: 981: 975:255.255.255.255 974: 973: 963: 962: 955: 954: 947: 946: 939: 938: 919: 918: 909: 908: 883: 882: 876:255.255.255.224 875: 874: 867: 866: 861: 848: 844: 840: 836: 828: 827: 824: 821: 818: 815: 812: 809: 806: 803: 800: 797: 794: 791: 788: 785: 782: 779: 776: 773: 770: 767: 764: 761: 758: 755: 752: 749: 746: 743: 740: 737: 734: 731: 728: 725: 722: 719: 716: 713: 710: 707: 704: 701: 698: 695: 692: 689: 686: 683: 680: 677: 674: 671: 668: 665: 662: 659: 652: 648: 645: 644: 641: 638: 635: 632: 629: 626: 620: 619: 616: 613: 610: 607: 604: 601: 597:is declared as 594: 590: 586: 582: 578: 575: 574: 571: 568: 565: 562: 559: 556: 553: 550: 547: 544: 541: 535:stencil buffers 530: 519: 506: 501: 495: 481: 480:, just like an 477: 473: 469: 465: 461: 457: 453: 449: 445: 441: 437: 433: 429: 418: 414: 408: 403: 398: 364: 360: 356: 352: 349: 344: 304: 300: 296: 292: 288: 284: 279:) than "masked 276: 269: 265: 261: 220: 219:is used with a 216: 212: 208: 204: 200: 191: 186: 182: 178: 130: 119: 113: 110: 67: 65: 51: 39: 28: 23: 22: 15: 12: 11: 5: 1563: 1553: 1552: 1536: 1535: 1509: 1508: 1506: 1503: 1502: 1501: 1496: 1494:Tagged pointer 1491: 1486: 1481: 1476: 1471: 1466: 1459: 1456: 1186: 1173: 1170: 1166:alpha channels 1089:Raster graphic 1071: 1068: 903:Mask example: 860: 857: 658: 625: 600: 540: 518: 515: 505: 502: 499: 489: 422:if and only if 411:(exclusive or) 402: 399: 372: 348: 345: 319: 268: 262: 236: 185: 179: 177: 174: 121: 120: 56:. Please help 42: 40: 33: 26: 9: 6: 4: 3: 2: 1562: 1551: 1548: 1547: 1545: 1524: 1523:PyImageSearch 1520: 1514: 1510: 1500: 1497: 1495: 1492: 1490: 1487: 1485: 1482: 1480: 1477: 1475: 1472: 1470: 1467: 1465: 1464:Affinity mask 1462: 1461: 1332:hash_function 1184: 1181: 1179: 1169: 1167: 1163: 1158: 1156: 1153: 1149: 1141: 1137: 1135: 1130: 1128: 1124: 1119: 1117: 1113: 1109: 1105: 1101: 1093: 1090: 1086: 1081: 1080:Clipping path 1077: 1067: 1065: 1057: 1042: 1041:means "any". 1040: 1025: 1022: 1020: 1012: 1009:255.255.255.0 1004: 996: 994: 991:255.255.255.0 986: 978: 969: 967: 959: 951: 943: 935: 930: 927: 924: 923: 914: 913: 904: 901: 899: 895: 891: 890:wildcard mask 887: 879: 871: 868:203.0.113.129 859:Inverse masks 856: 854: 834: 656: 623: 598: 538: 536: 528: 524: 510: 498: 493: 488: 485: 460:, it returns 427: 423: 412: 396: 392: 388: 384: 380: 376: 371: 368: 342: 338: 334: 330: 326: 322: 318: 316: 312: 307: 282: 274: 259: 255: 251: 247: 243: 239: 235: 233: 229: 224: 198: 197:the principle 194: 173: 171: 167: 163: 159: 155: 151: 147: 143: 139: 135: 128: 117: 106: 103: 99: 96: 92: 89: 85: 82: 78: 75: –  74: 70: 69:Find sources: 63: 59: 55: 49: 48: 47:single source 43:This article 41: 37: 32: 31: 19: 1527:. Retrieved 1525:. 2018-11-19 1522: 1513: 1407:HASH_BITMASK 1401:hashed_token 1374:hashed_token 1326:hashed_token 1272:HASH_BITMASK 1182: 1175: 1159: 1145: 1131: 1120: 1115: 1097: 1062:198.51.100.2 1059: 1048:198.51.100.2 1045: 1043: 1028: 1026: 1023: 1014: 1006: 998: 997: 988: 983:198.51.100.0 980: 972: 970: 961: 953: 945: 937: 931: 928: 925: 917: 915: 907: 905: 902: 897: 893: 881: 873: 865: 862: 841:unsigned int 829: 646: 621: 576: 520: 496: 491: 486: 428:of bits are 404: 394: 390: 389:000 = 0000 386: 382: 381:101 AND 0000 378: 374: 369: 350: 340: 336: 332: 328: 324: 320: 310: 308: 280: 272: 270: 257: 253: 249: 245: 241: 237: 227: 225: 187: 141: 137: 131: 111: 101: 94: 87: 80: 68: 44: 1419:token_array 1380:MAX_RECORDS 1356:NUM_BUCKETS 1293:token_array 1284:// (2^10)-1 1245:MAX_RECORDS 1236:// 2^32 - 1 1224:NUM_BUCKETS 1172:Hash tables 1127:bitwise AND 1070:Image masks 956:192.0.2.255 845:glClear(42) 478:Y XOR 0 = Y 470:0 XOR 1 = 1 468:it returns 462:1 XOR 1 = 0 413:operation. 313:the higher 305:Y AND 1 = Y 293:Y AND 0 = 0 230:the higher 166:predication 1529:2020-04-05 1505:References 1230:0xFFFFFFFF 1178:hash table 1134:bitwise OR 1074:See also: 837:GLbitfield 669:GLbitfield 611:GLbitfield 426:odd number 393:000 0000 385:000 0000 377:101 1001 205:Y OR 0 = Y 201:Y OR 1 = 1 114:April 2020 84:newspapers 1474:Bit field 1017:0.0.0.255 964:192.0.2.x 948:192.0.2.1 920:0.0.0.255 910:192.0.2.0 884:0.0.0.255 833:type-safe 653:glClear() 595:glClear() 531:glClear() 335:1111 = 327:0101 AND 252:0000 = 244:0101 OR 150:bit field 54:talk page 1544:Category 1458:See also 1323:uint32_t 1269:uint32_t 1254:<< 1242:uint32_t 1221:uint32_t 1194:#include 1188:#include 1123:run time 1076:Bit blit 952:through 940:192.0.2. 847:or even 417:returns 299:ed with 190:bitwise 1263:// 2^10 1150:), for 1148:sprites 1104:bitmaps 1092:sprites 1054:0.0.0.0 1031:0.0.0.0 872:with a 663:glClear 627:glClear 605:glClear 542:glClear 339:0101 331:1111 323:0101 256:0101 248:0000 240:0101 142:bitmask 98:scholar 18:Bitmask 1489:Subnet 1443:return 1392:size_t 1365:size_t 1344:strlen 934:octets 916:mask: 589:, and 527:OpenGL 315:nibble 232:nibble 158:nibble 100:  93:  86:  79:  71:  1499:umask 1434:token 1425:index 1404:& 1395:index 1386:// OR 1368:index 1350:token 1338:token 1311:token 1278:0x3FF 1266:const 1239:const 1218:const 1155:icons 1108:pixel 851:. In 798:& 762:& 726:& 690:& 343:0101 260:0101 199:that 105:JSTOR 91:books 1308:char 1299:NULL 1287:char 1209:void 1203:main 1164:and 1116:mask 1112:bits 1078:and 835:. A 795:bits 759:bits 723:bits 687:bits 672:bits 660:void 614:bits 602:void 593:and 397:000 373:1001 341:0000 337:0000 333:0000 329:0000 325:1010 321:1001 258:1111 254:1111 250:1111 246:1111 242:1010 238:1001 203:and 162:word 154:byte 138:mask 136:, a 77:news 1200:int 1152:GUI 1121:At 1098:In 853:C++ 649:and 474:XOR 450:XOR 424:an 415:XOR 409:XOR 353:AND 311:off 303:as 297:AND 289:AND 273:off 168:in 140:or 132:In 60:by 1546:: 1521:. 1359:); 1353:), 1290:** 1257:10 1066:" 1005:- 995:. 807:!= 792:(( 789:if 771:!= 756:(( 753:if 735:!= 720:(( 717:if 699:!= 684:(( 681:if 642:); 617:); 585:, 581:, 569:); 484:. 482:OR 367:. 281:on 228:on 223:. 217:OR 209:OR 192:OR 160:, 156:, 1532:. 1452:} 1449:; 1446:0 1437:; 1431:= 1428:) 1422:+ 1416:( 1413:* 1410:; 1398:= 1383:; 1377:% 1371:= 1347:( 1341:, 1335:( 1329:= 1320:; 1314:= 1302:; 1296:= 1281:; 1275:= 1260:; 1251:1 1248:= 1233:; 1227:= 1215:{ 1212:) 1206:( 1051:/ 1034:/ 960:( 898:1 894:0 825:} 822:} 816:{ 813:) 810:0 804:) 786:} 780:{ 777:) 774:0 768:) 750:} 744:{ 741:) 738:0 732:) 714:} 708:{ 705:) 702:0 696:) 678:{ 675:) 666:( 636:| 630:( 608:( 566:0 563:, 560:0 557:, 554:1 551:, 548:1 545:( 523:C 466:0 458:1 454:1 446:1 442:1 438:0 434:1 430:1 419:1 395:0 391:1 387:1 383:1 379:0 375:1 365:0 361:0 357:0 301:1 285:1 277:0 266:0 221:0 213:1 183:1 129:. 116:) 112:( 102:· 95:· 88:· 81:· 64:. 50:. 20:)

Index

Bitmask

single source
talk page
improve this article
introducing citations to additional sources
"Mask" computing
news
newspapers
books
scholar
JSTOR
Masking (disambiguation)
computer science
bitwise operations
bit field
byte
nibble
word
predication
vector processing
bitwise OR
the principle
nibble
nibble
XOR (exclusive or)
if and only if
odd number

C

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.