Your question is not entirely clear, but hopefully my interpretation of it will be of some value to you.
The "value" of this number is decimal 11.
However, [...] the above [...] may instead be seen as 4 switches
So, both the binary and the decimal number system are based on the same principle; the difference is in the number of available digits.
The binary number system has 2 symbols for digits (conventionally 0 and 1, but it could really be any two distinct things, as long as one is interpreted as "zero", and the other as "one"), so it is base 2 (I'll go into more detail on what that means in a second).
The decimal system uses 10 different symbols (0-9), and is base 10.
When a number is written as a string of digits
each digit has an implicit multiplier based on it's position; if you index the rightmost digit (least significant digit) as 0, and then increase the indices towards the left, the implicit multiplier is
^ is "to the power of" operator); the value of the number is the sum.
For example, the decimal number 123 is actually:
(1 * 10^2) + (2 * 10^1) + (3 * 10^0) == (1 * 100) +(2 * 10) + (3 * 1)
(parentheses added for readability)
You probably know this as ones, tens, hundreds, thousands, etc.
Similarly, the binary number 1011 is:
(1 * 2^3) + (0 * 2^2) + (1 * 2^1) + (1 * 2^0)
or in decimal:
== (1 * 8) + (0 * 4) + (1 * 2) + (1 * 1)
== 8 + 0 + 2 + 1 == 11
Instead of ones, tens, hundreds, ..., you now have ones, twos, fours, eights, etc.
So, it works the same way, except that with decimal it's not a series of two-state switches, but more like a bunch of dials with 10 different positions each. Note that in binary, since the digits are either 0 or 1, the terms in the sum are either zeros or the corresponding powers of 2 (while in decimal, the terms can be any 0-9 multiple of the corresponding power of 10).
The "value" of this number is decimal 11.
One way to think about it is that the value of both numbers is "eleven" (the abstract concept) - it's just that in the binary number system, that value is represented as "1011", while in decimal it is represented as "11".
We want to set the second-to-highest bit to 1 like this:
This is just a consequence of how bitwise OR works - it's a Boolean OR applied to each bit pair.
In decimal, we performed 150 OR 64 to get 214. We added 64 to the value of 150 which creates the number 214
So, while that's not exactly wrong, it isn't quite right either, and it doesn't really describe what happened. The number 64 is a power of 2 (
64 == 2^6), and you happened to change the seventh bit from the right (so, at index 6) from 0 to 1, and that in turn added that power of 2 to the total sum. Furthermore, the second number had only a single digit with the value 1 (the seventh one), and this is why it was 64. But, you could have gotten the same result like this:
0100 0100 // 68
Is it beneficial as a programmer to look at the decimal values of
these bitwise interactions, or is there no real use in that, and
instead, they are typically viewed simply as positional bit flips to
Well, in general, there isn't necessarily going to be something interesting when doing these conversions, but there are some tricks that you may occasionally use.
First, if you are going to work with and manipulate binary values, it's beneficial to learn the hexadecimal number system, because each hex digit corresponds to one of the possible 4-bit strings (or half a byte - a.k.a. a nibble). See this - you don't necessarily have to memorize the nibbles associated with each hex digit; you can look these tables up if you need them. These can be used to set binary values, or as "masks" during bit manipulation. Also, it will come in handy if you ever need to use a hex editor, and it can help with some other things - like understanding hex color codes in css.
It is also beneficial to learn the powers of 2 (in decimal or hex), as these can be used as "flags" (they all have only a single bit set to 1 in binary representation).
Another trick that can sometimes come in handy is using bit shifting to perform multiplication by 2 (or a power of 2). Assuming unsigned numbers and no loss of data, shifting by one position to the left effectively multiplies the number by 2:
0101 << 1 == 1010 // or 5 --becomes--> 10
Similarly, shifting to the right divides by 2:
1010 >> 1 == 0101 // or 10 --becomes--> 5
0101 >> 1 == 0010 // or 5 --becomes--> 2 (integer division, loss of data, loss of accuracy)
Shifting by n positions multiplies or divides by 2^n. That said, in general, prefer clarity over cleverness in your code, especially if other people are going to read it. I.e., use regular multiplication most of the time, and leave hacks such as this one for situations that require such tricks - for example, this can be used to manipulate pixels of an image in place efficiently; also, when doing something hackish, add comments that clarify the intent (why you are doing it and what you are trying to achieve) - this will be helpful to anyone who is reading the code, including yourself, when you leave the project for a while (and forget the details of what you were doing) and then come back to it.