A bitfield is a method for storing a lot of yes/no, set/not_set, or on/off data in one integer. Because an integer is made up of 32 1s and 0s (bits), each of the 32 positions in an integer can be made to represent something. Essentially, it is a way of looking at an integer on the bit level where each bit is yes/no or on/off flag. Each of these bits in a bitfield is then a bitflag. When used with bitwise operators the results can be very powerful.

For example, if we want to describe fruit we might have a fruit bitfield. We could decide that the first bit (furthest right) is if it is round or not, the second bit is whether it is red or not and the third bit is whether it grows on a vine. Thus, an apple could be 011 or 3 (round, red and not grown on a vine), a grape could be 111 or 7 (round, red and grown on a vine), and a banana could be 000 or 0 (not round, not red and not grown on a vine). Each position is a power of 2 (remember 2^0 is 1).

If we wanted to see if a given fruit bitfield represented a round fruit we could use the following:

`if (myFruit & 1)`

To make it more legible we may define a set of global integers:

integer ROUND = 1; // 0001 binary integer RED = 2; // 0010 binary integer VINE = 4; // 0100 binary

Then the previous if can be stated in the very legible form:

`if (myFruit & ROUND)`

If we want to set a single field, or multiple fields, that is also easy:

myFruit = myFruit | ROUND

It's easier to work with bitfields with hex than decimal constants.

(edit: s/then/than/ ; not sure if this is what was meant, but scanning this sentence 20 times it's the most likely one. I can see it be 'then', but that doesn't make much sense.)

Functions or events that use bitfields include:

Boolean | Operators | Integer | Bitwise | Binary Jasa SEO Jasa SEO Murah Sepatu Online Toko Sepatu Online Sepatu Sepatu Murah Sepatu Safety Sepatu Futsal Cheapes Hostgator Coupon Link Booking Televisori offerte Notebook Offerte Berita Terkini Internet Marketer Muda Internet Marketer Indonesia Portatile Apple RDAnet Lorks Karikatur Bisnis Modal Kecil Bisnis UKM Berita Terbaru Iklan Baris Jasa SEO Jasa SEO Murah SEO Indonesia Konsultan SEO SEO Belajar SEO Kursus SEO Kursus SEO Murah Jam Tangan Casio Jam Tangan Casio Jam Tangan Murah Jam Tangan Grosir Baju Terbaru Grosir Baju Baju Terbaru Grosir Baju Murah Bisnis Online Belajar SEO Kerupuk Kerupuk kulit Social Bookmark Dofollow Social Bookmark Kumpulan Puisi Kirim Puisi bola hantu Penumbuh Rambut Penumbuh Rambut timbangan WBC Wonogiri Jasa SEO Murah Jasa SEO Jam Tangan Murah

There is one comment on this page.
[Display comments/form]