Features of the mql5 language, subtleties and tricks - page 304
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
No explanation!
The bug (?!) shows in the intermediate results ONLY (for all bitwise operators).
However, assignment (Num >>= 1) works as expected, (luckily).
All integral sub-types of int are processed internally as int.
All integral sub-types of int are processed internally as int.
The bitwise operators promote small integers (such as char/uchar) to signed ints. https://stackoverflow.com/a/28142065
The integral promotions of small integers do have side effects to be aware of. In the next example, the uchar/char value can be left shifted more than its width (<< more than 8-bits)
There also another issue with bitwise operators (Signed types):
When doing bitwise operations, if you want strictly well-defined (according to the standard) results, you generally have to ensure that the values being operated on are unsigned. You can do that either with explicit casts, or by using explicitly unsigned constants (U-suffix) in binary operations.
All integral subtypes of int are treated internally as int.
Thanks.
The bitwise operators promote small integers (such as char/uchar) to signed ints. https://stackoverflow.com/a/28142065
The integral promotions of small integers do have side effects to be aware of. In the next example, the uchar/char value can be left shifted more than its width (<< more than 8-bits)
There also another issue with bitwise operators (Signed types):
When doing bitwise operations, if you want strictly well-defined (according to the standard) results, you generally have to ensure that the values being operated on are unsigned. You can do that either with explicit casts, or by using explicitly unsigned constants (U-suffix) in binary operations.
It's probably better to avoid bitwise operations with char/uchar or short/ushort.
Why would you want to do that anyway ?
If you want to use bits to represent Tick data, just count how much bits you need and use enough int (or long ?) to match them. I don't have time to do it, but could be interesting.
Such a task.
Here https://www.mql5.com/en/forum/349798/page3#comment_57408237
Forum on trading, automated trading systems and testing trading strategies
Scripts: TickCompressor
amrali, 2025.07.04 02:54
TickCompressor v.0.1c: totally eliminated loss of precision by using fixed-point arithemtic (int) encoding for tick prices. (idea here from fxsaber)
Here https://www.mql5.com/en/forum/349798/page 3#comment_57408237
Try measuring the criterion for the effectiveness of your edits (taken from here).
Why does a bitwise operation lead to the creation of an int-variable?
How to do bitwise operations cheaply?
Is it the right thing to do?
Uploaded to this thread as it is autotranslate.
Learn the pluses and smile)))))))
https://en.cppreference.com/w/cpp/language/operator_arithmetic.html
Section Built-in bitwise shift operators
There we read: