Questions on OOP in MQL5 - page 92

 

Vladimir Simakov:

int CSetting::sign=1<<31;
int CSetting::_sign=1<<11;
int CSetting::mean=0xFFFFFFFF>>21;

YES!

I never would have guessed that variable values can be set by the necessary shift !

cool! thanks!

 

With complete economy of space:

void OnStart()
{

   int a=2; // 0,1,2
   int b=7; // 0,1,2
   int c=7; // 0,1,2,3,4,5,6,7
   int d=12345;  
   
   int v=a+b*3+c*(3*8)+d*(3*8*8);
   
   d=v/(3*8*8);
   v%=(3*8*8);
   
   c=v/(3*8);
   v%=(3*8);   
   
   b=v/3;
   a%=3;     
   
   Alert(a," ",b," ",c," ",d);
  
} 
 
Vladimir Simakov:

another question... Is there any way to get a 12 bit int via union ?... never mind how ))))

ZS: ideally a 9-15 bit int , the sign is not a problem, i.e. it is possible to unsigned int (in the last builds MQL has learnedunsigned int, it is possible to use instead of uint )

 

Icho:

void OnStart()
{
   int a=2; // 0,1,2
   int b=3; // 0,1,2
   int c=7; // 0,1,2,3,4,5,6,7
   int d=12345;  

   int v=(d<<8)|(c<<5)|(b<<2)|a;
   
   a=v&3;
   v>>=2;
   b=v&7;
   v>>=3;   
   c=v&7;  
   v>>=3;      
   d=v;
   
   Alert(a," ",b," ",c," ",d);

}
 
Igor Makanu:

another question... Is there any way to get a 12 bit int via union ?... never mind how ))))

ZS: 9-15 bit int ideally , the sign to allocate is not a problem, i.e. it is possible unsigned int (in last builds MQL has learnedunsigned int, it is possible instead of uint to use )

Probably not. There are no half byte variables yet.

 
Dmitry Fedoseev:

Probably not. There are no half bytes of variables yet.

Why not? Encode and mask the required bits, any number of bits can be used

but the problem is not to screw it up ;)

UPD: googling such a question, at least read what they advisehttps://stackoverflow.com/questions/29529979/10-or-12-bit-field-data-type-in-c

 
Igor Makanu:

Why not? encode and mask the required bits, any number of bits can be used

but the problem is not to screw it up ;)

Then you can do without union too.

 
Dmitry Fedoseev:

Then you can do without the union, too.

yes, union is more of a problem than a convenience

 

Any idea why the compiler uses the method in the base-class?

Files:
Code_it.mq5  2 kb
 
Nelson Wanyama:

Any idea why the compiler uses the method in the base-class?

Because you are not overriding a virtual function, you are using overloading.