100
votes
Why are bit masks called "masks" and what purpose do they serve?
A mask (of the facial variety) is something that covers up some parts of your face and lets other parts show through. The terminology is used by analogy in computing: a bitmask covers up (filters out)...
55
votes
Why are bit masks called "masks" and what purpose do they serve?
A bit mask is used to mask some bits of a bit field while exposing others:
initial value: 011011001
bit mask.....: 111110000
result value.: 011010000
This has been used before computing in ...
39
votes
Why are bit masks called "masks" and what purpose do they serve?
Bitmasks are terribly old. I haven't been able to find a reference to the first one, but they were certainly popular by the advent of 8-bit processors, and likely were also used in 4-bit processors.
...
13
votes
What's the purpose of multiplying by 1024x1024?
It's difficult to be (at all) certain without looking at the code, but it kind of sounds like it's implementing fixed-point arithmetic, with 12 bits before the decimal point, and 20 bits after.
When/...
9
votes
Why are bit masks called "masks" and what purpose do they serve?
A bit mask is similar to screen printing. You select some certain bit position to be taken over into the result:
source value = 42 -> 00101010b
mask = 51 -> 00110011b
result 42&51 = ...
8
votes
Accepted
Why is the bitwise AND of 1 and any even number equal to 0?
First, looking at decimal
In base 10, we can easily determine the parity of an integer (whether it is even or odd), by looking at the parity of the last digit:
If a base 10 numbers ends in 0, 2, 4, 6,...
8
votes
What is the viability of engineering an integral type with values ranging from -1 to 254? Do types like this even exist?
You're taking the use specifically of -1 too literally here. APIs like this didn't really pick -1; they're either picking any negative number, or they're picking an integer with all of its bits set (...
6
votes
What is the term for a integer variable containing bit fields?
An identifier (it doesn't need to vary) whose value is represented with an arbitrary length of bits has many names:
Bit string, bit vector, bit array, bitmask, bit map, bit set, ...
There is no single ...
5
votes
Accepted
How to understand and design functions with enumeration arguments that work in tandem with bitwise operators in C++ and Qt?
Your understanding is pretty good. To answer your questions:
Yes, it the function will receive 0x0000 0000 0000 0000 0000 1010 as an argument.
The significance of the decimal number 10 in binary is ...
5
votes
Accepted
In C++, Why do bitwise operators convert 8 or 16 bit integers to 32 bit?
The rule in C++, which was inherited from C, is that all operands that are smaller than int or unsigned int are first converted to one of those (with int being preferred if it can represent all values ...
5
votes
Accepted
Semantics of simulating a 64bit integer with two 32bit integers (hi, lo)
Given any system which supports standard math operations -- add, subtract, multiply, divide -- on n bits, you first need to keep in mind some rules. If you are using sign-magnitude representation you ...
5
votes
Do decimal equivalents to binary number values hold significance in software programming?
My question is: Is there any significance to the fact that the number we had to use to set that bit happens to be 64?
There is exactly the same significance to the fact that the ascii character we had ...
5
votes
Why is the bitwise AND of 1 and any even number equal to 0?
To see why, let's start by finishing the AND operation and viewing the results in binary:
00101 (5)
00001 (1)
-----&
00001 (1)
00100 (4)
00001 (1)
-----&
00000 (0)
When we AND a variable (...
4
votes
What's the purpose of multiplying by 1024x1024?
The fact that this shift is done one way and then in reverse later suggests that this is perhaps a hack to provide use extra bandwidth in these values. That is, the 20 low-order bits are being used ...
3
votes
Why are bit masks called "masks" and what purpose do they serve?
Another kind of physical mask in IT is the lithographic photomask used to etch away only part of a silicon wafer. That wasn’t used to manufacture the earliest computers, but anyone working in the ...
3
votes
Why is the bitwise AND of 1 and any even number equal to 0?
I'm not sure whether I'm covering the same ground as the existing answers, but cast your mind back to learning Hundreds, Tens, and Units in primary school.
That system, in which there are ten ...
3
votes
Are bitwise operators in C used both for bit operations and for operations for integer or some C types?
I think the main misconception expressed in this question here is that there is a difference between a "word of bits" (or bitset) and "integers" in C.
In short: there is not.
...
3
votes
What is the viability of engineering an integral type with values ranging from -1 to 254? Do types like this even exist?
I think what you are asking are valid questions - a little bit broad, but these questions are hard to separate from each other.
1: Does an integral type like this already exist somewhere?
Has it been ...
2
votes
Why are bit masks called "masks" and what purpose do they serve?
Bit masks were invented for a couple of reasons:
Hardware registers were mapped to a contiguous set of bits
Memory space was very limited in the not too distant past
When you look at how you see the ...
2
votes
Accepted
How can I query, increment & decrement arbitrary-length integers encoded into a bit-array?
Here's the start of a pseudocode solution for W = 4.
// beware: untested code ahead
uint64[] array;
int read(int i)
{
uint64 loaded = array[i / 16];
return (loaded >> ((i % 16) * 4)) &...
2
votes
Best practices for reading dynamic byte streams: is line-by-line comparison with a mask the best way?
When there are a limited number of field combinations that are sent relatively often, you can first do a switch on section header and jump to reading a canned sequence of fields.
In the default branch ...
2
votes
Accepted
What effects does memory space have on bitwise shifts?
Let’s generalize:
Suppose that you have n+1 digits, noted D0 to Dn starting with least significant one (i.e. starting on the right in our numeral conventions). Suppose that R is the radix used, so ...
2
votes
What effects does memory space have on bitwise shifts?
Bitwise shift is a pretty basic implementation. It is true that it doubles the value of unsigned integers. But that is not the case for other types of data. In the case of two's complement for ...
2
votes
C++ - BitVector logic
There is no correct answer here. Your memcpy() code reinterprets bit patterns using the machine's endianess, and exercises undefined behaviour. For your bit vector, you can decide whether you enforce ...
2
votes
Do decimal equivalents to binary number values hold significance in software programming?
Most things can be used in multiple ways. For example,
coins can be used as screwdrivers sometimes. But when a coin is used as a screwdriver, it doesn’t matter that the coin could also be used to buy ...
2
votes
Do decimal equivalents to binary number values hold significance in software programming?
Binary, octal, decimal, hexadecimal are only different means to express the same number.
So it’s not about a special significance, it’s just that 0100 0000 in binary, 64 in decimal and 0x40 in ...
2
votes
Do decimal equivalents to binary number values hold significance in software programming?
No, there is no meaningful relationship between the decimal and binary notations of the numbers. One is base 10 and the other base 2 and ten is not a power of two.
The reason we use base-10 Arabic ...
2
votes
In C++, Why do bitwise operators convert 8 or 16 bit integers to 32 bit?
The C++ Language specification follows the C language specification in being counter-intuitive here. Its defined so that when evaluating integer expressions everything is first converted to an int and ...
2
votes
What is the viability of engineering an integral type with values ranging from -1 to 254? Do types like this even exist?
We have types that solve this problem. They don’t have the long history of use that the -1 flag or the null pointer have but they work if you know how to use them.
Want to show an unsigned integer isn’...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
bitwise-operators × 57c++ × 11
c × 11
operators × 7
bit × 7
binary × 6
math × 5
programming-languages × 4
arithmetic × 4
low-level × 3
java × 2
c# × 2
performance × 2
terminology × 2
language-design × 2
efficiency × 2
c++11 × 2
assembly × 2
hashing × 2
enum × 2
boolean × 2
32-bit × 2
php × 1
database-design × 1
data-structures × 1