136:(in C23) or other implementation-defined types. In C++, they can be created using any integral or enumeration type; most C compilers also allow this. In this case, the programmer can declare a structure for a bit field which labels and determines the width of several subfields. Adjacently declared bit fields of the same type can then be packed by the compiler into a reduced number of words, compared with the memory used if each 'field' were to be declared separately.
687:
843:
These bits are set by the processor following the result of an operation. Certain bits (such as the Carry, Interrupt-disable, and
Decimal flags) may be explicitly controlled using set and clear instructions. Additionally, branching instructions are also defined to alter execution based on the current
108:
Bit fields can be used to reduce memory consumption when a program requires a number of integer variables which always will have low values. For example, in many systems, storing an integer value requires two bytes (16-bits) of memory; sometimes the values to be stored actually need only one or two
139:
For languages lacking native bit fields, or where the programmer wants control over the resulting bit representation, it is possible to manually manipulate bits within a larger word type. In this case, the programmer can set, test, and change the bits in the field using combinations of
902:
in binary) evaluates to 0x20. This means the flag bit is set i.e., the device has data ready. If the flag-bit had not been set, this would have evaluated to 0 i.e., there is no data available from the device.
95:
in that the latter is used to store a large set of bits indexed by integers and is often wider than any integral type supported by the language. Bit fields, on the other hand, typically fit within a machine
31:
which have been allocated for specific purposes, so that any single bit or group of bits within the structure can be set or inspected. A bit field is most commonly used to represent
755:
of a processor is a bit field consisting of several flag bits. Each flag bit describes information about the processor's current state. As an example, the status register of the
941:
Writing, reading or toggling bits in flags can be done only using the OR, AND and NOT operations – operations which can be performed quickly in the processor. To set a bit,
855:(Branch on oVerflow Set) instruction may be used to jump based on whether the overflow flag was set by the processor following the result of the addition instruction.
42:
The meaning of the individual bits within the field is determined by the programmer; for example, the first bit in a bit field (located at the field's
1303:
1053:
In C, it is implementation-defined whether a bit-field of type int is signed or unsigned. In C++, it is always signed to match the underlying type.
1259:
1232:
1204:
1177:
1150:
1120:
1084:
488:. For behavior that remains predictable across compilers, it may be preferable to emulate bit fields with a primitive and bit operators:
733:
1334:
997:
702:
1024:
715:
109:
bits. Having a number of these tiny variables share a bit field allows efficient packaging of data in the memory.
70:
66:
61:
that is composed of flags. For example, if the result of an addition cannot be represented in the destination an
162:
945:
the status byte with a mask byte. Any bits set in the mask byte or the status byte will be set in the result.
1308:
949:
81:
952:
the status byte and the mask byte. This will set a bit if it is cleared or clear a bit if it is set.
886:
If the status-byte from a device is 0x67 and the 5th flag bit indicates data-ready. The mask-byte is
485:
1293:
697:
57:
are commonly used to control or to indicate the outcome of particular operations. Processors have a
46:) is sometimes used to determine the state of a particular attribute associated with the bit field.
1009:
891:
880:
864:
756:
62:
32:
1021: – Register containing flags giving additional information concerning a result in a processor
991:
145:
1196:
Programming and
Designing with the 68000 Family: Including 68000, 68010/12, 68020, and the 68030
1112:
1255:
1228:
1200:
1173:
1146:
1116:
1080:
36:
1249:
1167:
1033:
1003:
942:
868:
141:
97:
1169:
Programming C# 4.0: Building
Windows, Web, and RIA Applications for the .NET 4.0 Framework
1018:
752:
85:
58:
1318:
1105:
24:
1328:
872:
65:
is set. The flags can be used to decide subsequent operations, such as conditional
43:
1036: – Processor register which changes or controls the general behavior of a CPU
1275:
1194:
1140:
1074:
961:
1012: – control register in IBM System/360 and successors systems architecture
979: – data structure commonly used in computer systems that play board games
708:
1142:
The 68000 Microprocessor Family: Architecture, Programming, and
Applications
985:
92:
1312:
879:
aligns a single bit to the nth position. Most also support the use of the
976:
967:
100:, and the denotation of bits is independent of their numerical index.
112:
In C, native implementation-defined bit fields can be created using
1076:
80386 Assembly
Language: A Complete Tutorial and Subroutine Library
166:
1298:
499:
Button order matches that of the
Nintendo Entertainment System. */
586:/* Clears the gameControllerStatus using AND and ~ (binary NOT)*/
680:
493:/* Each of these preprocessor directives defines a single bit,
50:
28:
1166:
Ian
Griffiths; Matthew Adams; Jesse Liberty (30 July 2010).
883:
operator (&) to isolate the value of one or more bits.
53:
and other logic devices, collections of bit fields called
914:, perform either of the following: (both are equivalent)
1029:
Pages displaying short descriptions of redirect targets
988: – Array data structure that compactly stores bits
972:
Pages displaying short descriptions of redirect targets
863:
A subset of flags in a flag field may be extracted by
1321:: Several snippets of C code manipulating bit fields
1014:
Pages displaying wikidata descriptions as a fallback
981:
Pages displaying wikidata descriptions as a fallback
1079:. McGraw-Hill School Education Group. p. 606.
71:
1104:
16:Data structure that maps one or more adjacent bits
496:corresponding to one button on the controller.
1098:
1096:
1000: – Base memory unit handled by a computer
35:of known, fixed bit-width, such as single-bit
8:
1218:
1216:
1134:
1132:
970: – Group of 32-bit RISC processor cores
544:/* Sets the gameControllerStatus using OR */
1027: – Status register of x86 architecture
964: – Encoding for data, using 0s and 1s
871:. A large number of languages support the
631:/* Tests whether a bit is set using AND */
1227:(5th ed.). Indianapolis, Ind: Sams.
734:Learn how and when to remove this message
1172:. "O'Reilly Media, Inc.". pp. 81–.
1006: – Data used for bitwise operations
761:
1065:
1046:
459:// Split a byte into 2 fields of 4 bits
1280:. W. Green. January 1986. p. 108.
1073:Penn Brumm; Don Brumm (August 1988).
231:#define WHITE (RED | GREEN | BLUE)
225:#define CYAN (GREEN | BLUE)
219:#define MAGENTA (RED | BLUE)
213:#define YELLOW (RED | GREEN)
7:
1248:Mark E. Daggett (13 November 2013).
91:A bit field is distinguished from a
88:was set by some previous operation.
1111:. "O'Reilly Media, Inc.". pp.
898:in binary) with the mask-byte 0x20(
80:(Jump if Equal) instruction in the
1139:Michael A. Miller (January 1992).
851:(Add with Carry) instruction, the
27:that maps to one or more adjacent
14:
925:)) != 0; bool nth_is_set = (
438:// fill to nearest byte (16 bits)
685:
480:The layout of bit fields in a C
859:Extracting bits from flag words
1199:. Prentice Hall. p. 275.
994: – Computer data variable
1:
1299:Description from another wiki
523:#define KEY_A 0b10000000
520:#define KEY_B 0b01000000
517:#define KEY_SELECT 0b00100000
514:#define KEY_START 0b00010000
511:#define KEY_UP 0b00001000
508:#define KEY_DOWN 0b00000100
505:#define KEY_LEFT 0b00000010
502:#define KEY_RIGHT 0b00000001
998:Word (computer architecture)
937:Changing bits in flag words
705:. The specific problem is:
303:// bit field box properties
1351:
1025:FLAGS register (computing)
875:operator (<<) where
847:For an instance, after an
759:processor is shown below:
701:to meet Knowledge (XXG)'s
747:Processor status register
161:Declaring a bit field in
84:will result in a jump if
1254:. Apress. pp. 68–.
1145:. Merrill. p. 323.
490:
171:
1304:Use case in a C++ guide
1294:Explanation from a book
1223:Prata, Stephen (2007).
1107:Practical C Programming
1103:Steve Oualline (1997).
910:th bit from a variable
1309:C++ libbit bit library
894:the status-byte 0x67 (
486:implementation-defined
157:C programming language
825:nterrupt-disable flag
763:6502 status register
82:x86 assembly language
1193:Tibet Mimar (1991).
716:improve this article
664:gameControllerStatus
613:gameControllerStatus
571:gameControllerStatus
532:gameControllerStatus
1335:Bit data structures
1319:Bit Twiddling Hacks
1010:Program status word
917:bool nth_is_set = (
764:
285:"Magenta"
204:#define RED 0b001
201:#define GREEN 0b010
198:#define BLUE 0b100
134:unsigned _BitInt(N)
63:arithmetic overflow
992:Flag (programming)
921:& (1 <<
762:
273:"Yellow"
174:// opaque and show
146:bitwise operations
1261:978-1-4302-6097-4
1251:Expert JavaScript
1234:978-0-672-32696-7
1206:978-0-13-731498-0
1179:978-1-4493-9972-6
1152:978-0-02-381560-7
1122:978-1-56592-306-5
1086:978-0-8306-9047-3
948:To toggle a bit,
844:state of a flag.
841:
840:
744:
743:
736:
703:quality standards
694:This article may
366:// fill to 8 bits
297:"White"
267:"Green"
255:"Black"
210:#define BLACK 0
195:// primary colors
86:the Z (zero) flag
69:. For example, a
67:jump instructions
1342:
1282:
1281:
1272:
1266:
1265:
1245:
1239:
1238:
1220:
1211:
1210:
1190:
1184:
1183:
1163:
1157:
1156:
1136:
1127:
1126:
1110:
1100:
1091:
1090:
1070:
1054:
1051:
1034:Control register
1030:
1015:
1004:Mask (computing)
982:
973:
901:
897:
889:
878:
854:
850:
765:
739:
732:
728:
725:
719:
689:
688:
681:
677:
674:
671:
668:
665:
662:
659:
656:
653:
650:
647:
644:
641:
638:
635:
632:
629:
626:
623:
620:
617:
614:
611:
608:
605:
602:
599:
596:
593:
590:
587:
584:
581:
578:
575:
572:
569:
566:
563:
560:
557:
554:
551:
548:
545:
542:
539:
536:
533:
530:
527:
524:
521:
518:
515:
512:
509:
506:
503:
500:
497:
494:
483:
475:
472:
469:
466:
463:
460:
457:
454:
451:
448:
445:
442:
439:
436:
433:
430:
427:
424:
421:
418:
415:
412:
409:
406:
403:
400:
397:
394:
391:
388:
385:
382:
379:
376:
373:
370:
367:
364:
361:
358:
355:
352:
349:
346:
343:
340:
337:
334:
331:
328:
325:
322:
319:
316:
313:
310:
307:
304:
301:
298:
295:
292:
291:"Cyan"
289:
286:
283:
280:
279:"Blue"
277:
274:
271:
268:
265:
262:
259:
256:
253:
250:
247:
244:
241:
238:
235:
232:
229:
226:
223:
220:
217:
214:
211:
208:
205:
202:
199:
196:
193:
192:#define DASHED 3
190:
189:#define DOTTED 2
187:
186:#define SOLID 1
184:
181:
178:
175:
135:
131:
127:
123:
119:
115:
78:
77:
74:
1350:
1349:
1345:
1344:
1343:
1341:
1340:
1339:
1325:
1324:
1313:alternative URL
1290:
1285:
1274:
1273:
1269:
1262:
1247:
1246:
1242:
1235:
1222:
1221:
1214:
1207:
1192:
1191:
1187:
1180:
1165:
1164:
1160:
1153:
1138:
1137:
1130:
1123:
1102:
1101:
1094:
1087:
1072:
1071:
1067:
1063:
1058:
1057:
1052:
1048:
1043:
1028:
1019:Status register
1013:
980:
971:
958:
939:
934:
899:
895:
887:
876:
861:
852:
848:
753:status register
749:
740:
729:
723:
720:
713:
690:
686:
679:
678:
675:
672:
669:
666:
663:
660:
657:
654:
651:
648:
645:
642:
639:
636:
633:
630:
627:
624:
621:
618:
615:
612:
609:
606:
603:
600:
597:
594:
591:
588:
585:
582:
579:
576:
573:
570:
567:
564:
561:
558:
555:
552:
549:
546:
543:
540:
537:
534:
531:
528:
525:
522:
519:
516:
513:
510:
507:
504:
501:
498:
495:
492:
481:
479:
477:
476:
473:
470:
467:
464:
461:
458:
455:
452:
449:
446:
443:
440:
437:
434:
431:
428:
425:
422:
419:
416:
413:
410:
407:
404:
401:
398:
395:
392:
389:
386:
383:
380:
377:
374:
371:
368:
365:
362:
359:
356:
353:
350:
347:
344:
341:
338:
335:
332:
329:
326:
323:
320:
317:
314:
311:
308:
305:
302:
299:
296:
293:
290:
287:
284:
281:
278:
275:
272:
269:
266:
263:
261:"Red"
260:
257:
254:
251:
248:
245:
242:
239:
236:
233:
230:
227:
224:
221:
218:
215:
212:
209:
207:// mixed colors
206:
203:
200:
197:
194:
191:
188:
185:
182:
179:
176:
173:
159:
154:
133:
129:
125:
121:
117:
113:
106:
75:
72:
59:status register
17:
12:
11:
5:
1348:
1346:
1338:
1337:
1327:
1326:
1323:
1322:
1316:
1306:
1301:
1296:
1289:
1288:External links
1286:
1284:
1283:
1267:
1260:
1240:
1233:
1212:
1205:
1185:
1178:
1158:
1151:
1128:
1121:
1092:
1085:
1064:
1062:
1059:
1056:
1055:
1045:
1044:
1042:
1039:
1038:
1037:
1031:
1022:
1016:
1007:
1001:
995:
989:
983:
974:
965:
957:
954:
938:
935:
916:
900:0010 0000
896:0110 0111
860:
857:
839:
838:
832:
826:
820:
814:
808:
805:
798:
791:
790:
787:
784:
781:
778:
775:
772:
769:
748:
745:
742:
741:
693:
691:
684:
491:
183:// line styles
172:
158:
155:
153:
150:
105:
104:Implementation
102:
33:integral types
25:data structure
15:
13:
10:
9:
6:
4:
3:
2:
1347:
1336:
1333:
1332:
1330:
1320:
1317:
1314:
1310:
1307:
1305:
1302:
1300:
1297:
1295:
1292:
1291:
1287:
1279:
1278:
1271:
1268:
1263:
1257:
1253:
1252:
1244:
1241:
1236:
1230:
1226:
1225:C primer plus
1219:
1217:
1213:
1208:
1202:
1198:
1197:
1189:
1186:
1181:
1175:
1171:
1170:
1162:
1159:
1154:
1148:
1144:
1143:
1135:
1133:
1129:
1124:
1118:
1114:
1109:
1108:
1099:
1097:
1093:
1088:
1082:
1078:
1077:
1069:
1066:
1060:
1050:
1047:
1040:
1035:
1032:
1026:
1023:
1020:
1017:
1011:
1008:
1005:
1002:
999:
996:
993:
990:
987:
984:
978:
975:
969:
966:
963:
960:
959:
955:
953:
951:
946:
944:
936:
932:
928:
924:
920:
915:
913:
909:
906:To check the
904:
893:
884:
882:
874:
870:
866:
858:
856:
845:
836:
833:
830:
827:
824:
821:
818:
815:
812:
809:
806:
803:
799:
796:
793:
792:
788:
785:
782:
779:
776:
773:
770:
767:
766:
760:
758:
754:
746:
738:
735:
727:
717:
712:
710:
704:
700:
699:
692:
683:
682:
489:
487:
180:#define NO 0
177:#define YES 1
170:
168:
164:
156:
151:
149:
147:
143:
137:
110:
103:
101:
99:
94:
89:
87:
83:
79:
68:
64:
60:
56:
52:
47:
45:
40:
38:
34:
30:
26:
22:
1276:
1270:
1250:
1243:
1224:
1195:
1188:
1168:
1161:
1141:
1106:
1075:
1068:
1049:
947:
940:
930:
926:
922:
918:
911:
907:
905:
885:
877:1 << n
862:
846:
842:
834:
828:
822:
816:
810:
801:
797:egative flag
794:
750:
730:
721:
714:Please help
706:
695:
478:
411:border_style
393:border_color
160:
138:
118:unsigned int
111:
107:
90:
54:
48:
44:base address
41:
20:
18:
962:Binary code
933:) & 1;
819:ecimal flag
804:erflow flag
718:if you can.
707:moved from
592:KeyReleased
375:show_border
1061:References
888:2^5 = 0x20
837:arry flag
709:Flag field
550:KeyPressed
339:fill_color
130:_BitInt(N)
128:(in C99),
122:signed int
986:Bit array
929:>>
813:reak flag
640:IsPressed
234:/* 111 */
228:/* 110 */
222:/* 101 */
216:/* 011 */
93:bit array
21:bit field
1329:Category
977:Bitboard
968:Bit-band
956:See also
831:ero flag
724:May 2016
696:require
646:unsigned
634:unsigned
598:unsigned
556:unsigned
526:unsigned
441:unsigned
423:unsigned
405:unsigned
387:unsigned
369:unsigned
351:unsigned
333:unsigned
315:unsigned
309:BoxProps
152:Examples
37:Booleans
1277:InCider
867:with a
698:cleanup
142:masking
49:Within
1258:
1231:
1203:
1176:
1149:
1119:
1083:
892:ANDing
865:ANDing
789:Bit 0
661:return
616:&=
482:struct
462:height
321:opaque
306:struct
246:colors
1041:Notes
873:shift
786:Bit 1
783:Bit 2
780:Bit 3
777:Bit 4
774:Bit 5
771:Bit 6
768:Bit 7
667:&
447:width
237:const
126:_Bool
55:flags
23:is a
1256:ISBN
1229:ISBN
1201:ISBN
1174:ISBN
1147:ISBN
1117:ISBN
1081:ISBN
869:mask
757:6502
751:The
649:char
637:char
601:char
589:void
559:char
547:void
529:char
444:char
426:char
240:char
165:and
144:and
98:word
51:CPUs
29:bits
1115:–.
1113:403
950:XOR
881:AND
853:BVS
849:ADC
670:key
652:key
622:key
604:key
577:key
562:key
484:is
408:int
390:int
372:int
354:int
336:int
318:int
167:C++
114:int
76:...
1331::
1215:^
1131:^
1095:^
943:OR
890:.
574:|=
474:};
300:};
169::
148:.
132:,
124:,
120:,
116:,
73:JE
39:.
19:A
1315:)
1311:(
1264:.
1237:.
1209:.
1182:.
1155:.
1125:.
1089:.
931:n
927:v
923:n
919:v
912:v
908:n
835:C
829:Z
823:I
817:D
811:B
807:-
802:V
800:o
795:N
737:)
731:(
726:)
722:(
711:.
676:}
673:;
658:{
655:)
643:(
628:}
625:;
619:~
610:{
607:)
595:(
583:}
580:;
568:{
565:)
553:(
541:;
538:0
535:=
471:;
468:4
465::
456:,
453:4
450::
435:;
432:0
429::
420:;
417:2
414::
402:;
399:3
396::
384:;
381:1
378::
363:;
360:4
357::
348:;
345:3
342::
330:;
327:1
324::
312:{
294:,
288:,
282:,
276:,
270:,
264:,
258:,
252:{
249:=
243:*
163:C
Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.