What does this = operator mean in C?
The expression set >>= 1;
means set = set >> 1;
that is right shift bits of set
by 1
(self assigned form of >>
bitwise right shift operator check Bitwise Shift Operators).
Suppose if set
is:
BIT NUMBER 31 n=27 m=17 0
▼ ▼ ▼ ▼
set = 0000 1111 1111 1110 0000 0000 0000 0000
Then after set >> = 1;
variable set
becomes:
BIT NUMBER 31 n=26 m=16 0
▼ ▼ ▼ ▼
set = 0000 0111 1111 1111 0000 0000 0000 0000
Notice the bits number shifted.
Note a interesting point: Because set
is unsigned long
so this >>
operation should be logical shift( unsigned shift) a logical shift does not preserve a number's sign bit.
Additionally, because you are shifting all bits to right (towards lower significant number) so one right shift is = divide number by two.
check this code (just to demonstrate last point):
int main(){
unsigned long set = 268304384UL;
set >>= 1;
printf(" set :%lu \n", set);
set = 268304384UL;
set /= 2;
printf(" set :%lu \n", set);
return 1;
}
And output:
set :134152192
set :134152192
(note: its doesn't means >>
and /
are both same)
Similarly you have operator <<=
for left shift, check other available Bitwise operators and Compound assignment operators, also check section: bit expressions and difference between: signed/arithmetic shift and unsigned shift.
What's the meaning of = (an arrow formed from equals & greater than) in JavaScript?
What It Is
This is an arrow function. Arrow functions are a short syntax, introduced by ECMAscript 6, that can be used similarly to the way you would use function expressions. In other words, you can often use them in place of expressions like function (foo) {...}
. But they have some important differences. For example, they do not bind their own values of this
(see below for discussion).
Arrow functions are part of the ECMAscript 6 specification. They are not yet supported in all browsers, but they are partially or fully supported in Node v. 4.0+ and in most modern browsers in use as of 2018. (I’ve included a partial list of supporting browsers below).
You can read more in the Mozilla documentation on arrow functions.
From the Mozilla documentation:
An arrow function expression (also known as fat arrow function) has a shorter syntax compared to function expressions and lexically binds the
this
value (does not bind its ownthis
,arguments
,super
, ornew.target
). Arrow functions are always anonymous. These function expressions are best suited for non-method functions and they can not be used as constructors.
A Note on How this
Works in Arrow Functions
One of the most handy features of an arrow function is buried in the text above:
An arrow function... lexically binds the
this
value (does not bind its ownthis
...)
What this means in simpler terms is that the arrow function retains the this
value from its context and does not have its own this
. A traditional function may bind its own this
value, depending on how it is defined and called. This can require lots of gymnastics like self = this;
, etc., to access or manipulate this
from one function inside another function. For more info on this topic, see the explanation and examples in the Mozilla documentation.
Example Code
Example (also from the docs):
var a = [
"We're up all night 'til the sun",
"We're up all night to get some",
"We're up all night for good fun",
"We're up all night to get lucky"
];
// These two assignments are equivalent:
// Old-school:
var a2 = a.map(function(s){ return s.length });
// ECMAscript 6 using arrow functions
var a3 = a.map( s => s.length );
// both a2 and a3 will be equal to [31, 30, 31, 31]
Notes on Compatibility
You can use arrow functions in Node, but browser support is spotty.
Browser support for this functionality has improved quite a bit, but it still is not widespread enough for most browser-based usages. As of December 12, 2017, it is supported in current versions of:
- Chrome (v. 45+)
- Firefox (v. 22+)
- Edge (v. 12+)
- Opera (v. 32+)
- Android Browser (v. 47+)
- Opera Mobile (v. 33+)
- Chrome for Android (v. 47+)
- Firefox for Android (v. 44+)
- Safari (v. 10+)
- iOS Safari (v. 10.2+)
- Samsung Internet (v. 5+)
- Baidu Browser (v. 7.12+)
Not supported in:
- IE (through v. 11)
- Opera Mini (through v. 8.0)
- Blackberry Browser (through v. 10)
- IE Mobile (through v. 11)
- UC Browser for Android (through v. 11.4)
- QQ (through v. 1.2)
You can find more (and more current) information at CanIUse.com (no affiliation).
What does the /= operator mean in Python?
It's an assignment operator shorthand for /
and =
.
Example:
x = 12
x /= 3
# equivalent to
x = x / 3
If you use help('/=')
, you can get the full amount of symbols supported by this style of syntax (including but not limited to +=
, -=
, and *=
), which I would strongly encourage.
What is the -- operator in C++?
-->
is not an operator. It is in fact two separate operators, --
and >
.
The conditional's code decrements x
, while returning x
's original (not decremented) value, and then compares the original value with 0
using the >
operator.
To better understand, the statement could be written as follows:
while( (x--) > 0 )
What does operator ~= mean in Lua?
the ~=
is not equals
It is the equivalent in other languages of !=
^=, -= and += symbols in Python
As almost any modern language, Python has assignment operators
so they can use them every time you want to assign a value to a variable after doing some arithmetic or logical operation, both (assignment and operation) are expressed in a compact way in one statement...
Table from Tutorials Point:
Operator Description Example = Assigns values from right side operands to left side operand c = a + b assigns value of a + b into c += Add AND It adds right operand to the left operand and assign the result to left operand c += a is equivalent to c = c + a -= Subtract AND It subtracts right operand from the left operand and assign the result to left operand c -= a is equivalent to c = c - a *= Multiply AND It multiplies right operand with the left operand and assign the result to left operand c *= a is equivalent to c = c * a /= Divide AND It divides left operand with the right operand and assign the result to left operand c /= a is equivalent to c = c / a %= Modulus AND It takes modulus using two operands and assign the result to left operand c %= a is equivalent to c = c % a **= Exponent AND Performs exponential (power) calculation on operators and assign value to the left operand c **= a is equivalent to c = c ** a //= Floor Division It performs floor division on operators and assign value to the left operand c //= a is equivalent to c = c // a What does ` ` mean in Python?
It means not equal to. It was taken from
ABC
(python's predecessor) see here:
x < y, x <= y, x >= y, x > y, x = y, x <> y, 0 <= d < 10
Order tests (
<>
means 'not equals')I believe
ABC
took it from Pascal, a language Guido began programming with.It has now been removed in Python 3. Use
!=
instead. If you are CRAZY you can scrap!=
and allow only<>
in Py3K using this easter egg:>>> from __future__ import barry_as_FLUFL
>>> 1 != 2
File "<stdin>", line 1
1 != 2
^
SyntaxError: with Barry as BDFL, use '<>' instead of '!='
>>> 1 <> 2
TrueWhat does the += operator do in Java?
The "common knowledge" of programming is that
x += y
is an equivalent shorthand notation ofx = x + y
. As long asx
andy
are of the same type (for example, both areint
s), you may consider the two statements equivalent.However, in Java,
x += y
is not identical tox = x + y
in general.If
x
andy
are of different types, the behavior of the two statements differs due to the rules of the language. For example, let's havex == 0
(int) andy == 1.1
(double):int x = 0;
x += 1.1; // just fine; hidden cast, x == 1 after assignment
x = x + 1.1; // won't compile! 'cannot convert from double to int'
+=
performs an implicit cast, whereas for+
you need to explicitly cast the second operand, otherwise you'd get a compiler error.Quote from Joshua Bloch's Java Puzzlers:
(...) compound assignment expressions automatically cast the result of
the computation they perform to the type of the variable on their
left-hand side. If the type of the result is identical to the type of
the variable, the cast has no effect. If, however, the type of the
result is wider than that of the variable, the compound
assignment operator performs a silent narrowing primitive
conversion [JLS 5.1.3].
Related Topics
How Is Std::String Implemented
How to Concatenate Two Strings in C++
Is It Legal to Recurse into Main() in C++
Resolution of Std::Chrono::High_Resolution_Clock Doesn't Correspond to Measurements
High Resolution Timer With C++ and Linux
Which C I/O Library Should Be Used in C++ Code
Why Does Call-By-Value Example Not Modify Input Parameter
C/C++ Include Header File Order
A Free Tool to Check C/C++ Source Code Against a Set of Coding Standards
Why Can Lambdas Be Better Optimized by the Compiler Than Plain Functions
How to Printf Uint64_T? Fails With: "Spurious Trailing '%' in Format"
Semantics of Flags on Basic_Ios
Why Is the C++ Initializer_List Behavior For Std::Vector and Std::Array Different