forked from nique_372/TsnTables
136 lines
5 KiB
MQL5
136 lines
5 KiB
MQL5
|
|
//+------------------------------------------------------------------+
|
||
|
|
//| H.mqh |
|
||
|
|
//| Copyright 2026, Niquel Mendoza |
|
||
|
|
//| https://www.mql5.com |
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
#property copyright "Copyright 2026, Niquel Mendoza"
|
||
|
|
#property link "https://www.mql5.com"
|
||
|
|
#property strict
|
||
|
|
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
//| |
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
#ifndef TSNTABES_SRC_BITS_H_MQH
|
||
|
|
#define TSNTABES_SRC_BITS_H_MQH
|
||
|
|
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
//| |
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
namespace TSN
|
||
|
|
{
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
//| |
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
// Clase statica de bick tricks del ecoistema
|
||
|
|
// aqui se ubican funciones de los bicktricts
|
||
|
|
// aqiu solo estaran las funciones "complejas, osea que requiern muchas lineas.. y no
|
||
|
|
// tendria mucho snrido o ensuciara la lecutra el usar #define \\\ extendido..
|
||
|
|
// las que no estan aqui (pro jeemplok CTZ) oi compact etc
|
||
|
|
// estan como defines (maxima velocida)
|
||
|
|
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
//| |
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
class CBitTricks
|
||
|
|
{
|
||
|
|
public:
|
||
|
|
CBitTricks(void) {}
|
||
|
|
~CBitTricks(void) {}
|
||
|
|
|
||
|
|
|
||
|
|
//--- CLZ
|
||
|
|
static int CLZ(ulong x);
|
||
|
|
static int CLZ(long x);
|
||
|
|
static int CLZ(datetime x);
|
||
|
|
static int CLZ(color x);
|
||
|
|
static int CLZ(int x);
|
||
|
|
static int CLZ(uint x);
|
||
|
|
static int CLZ(ushort x);
|
||
|
|
static int CLZ(short x);
|
||
|
|
static int CLZ(char x);
|
||
|
|
static int CLZ(uchar x);
|
||
|
|
|
||
|
|
//---
|
||
|
|
template <typename T>
|
||
|
|
static string ToBitsBE(T v);
|
||
|
|
|
||
|
|
//---
|
||
|
|
template <typename T>
|
||
|
|
static bool ByteHighNumberEstaPrendido(T x);
|
||
|
|
};
|
||
|
|
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
//| |
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
// Aqui iran las definciiones H (header)
|
||
|
|
// y tambien el cuerpo de alguans funciones que no reuqin explciacion o algo mas complejo tipo tablas..
|
||
|
|
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
//| |
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
template <typename T>
|
||
|
|
static string CBitTricks::ToBitsBE(T v)
|
||
|
|
{
|
||
|
|
string str;
|
||
|
|
StringInit(str, ((sizeof(T) << 3)), '0'); // reservamos una vez...
|
||
|
|
for(int i = (sizeof(T) << 3) - 1 ; i >= 0; i--)
|
||
|
|
{
|
||
|
|
if((v & (1ULL << i)) != 0)
|
||
|
|
str.SetChar(i, '1');
|
||
|
|
}
|
||
|
|
return str;
|
||
|
|
}
|
||
|
|
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
//| |
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
// Al final probadno descrubri que esto es mas rapido uqe usar CLZ y luego encontrar eel indice y eso
|
||
|
|
// asi que lo usare...
|
||
|
|
template <typename T>
|
||
|
|
static bool CBitTricks::ByteHighNumberEstaPrendido(T x)
|
||
|
|
{
|
||
|
|
//---
|
||
|
|
if(x == 0)
|
||
|
|
return false;
|
||
|
|
|
||
|
|
//---
|
||
|
|
T valor = x;
|
||
|
|
int idx = 0;
|
||
|
|
if(valor >= 0x100000000)
|
||
|
|
{
|
||
|
|
idx += 4;
|
||
|
|
valor >>= 32;
|
||
|
|
}
|
||
|
|
if(valor >= 0x10000)
|
||
|
|
{
|
||
|
|
idx += 2;
|
||
|
|
valor >>= 16;
|
||
|
|
}
|
||
|
|
if(valor >= 0x100)
|
||
|
|
{
|
||
|
|
idx += 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
//---
|
||
|
|
return (uchar((x >> (idx << 3))) & 0x80) != 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
//| |
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
// 1. Notas estuve trabadto de usar StrginSetLenght
|
||
|
|
// Y note que no funciaon pro lo visto esa funcion solo cambia el "integer"
|
||
|
|
// que reprensetar el len.. pero solo reduce no aumenta ni nada
|
||
|
|
// como truncar...
|
||
|
|
// 2. StringInit por su parte lo qeu hace es inicar y reservar memoria de verdad
|
||
|
|
// pero por lo visto hay un tema el \0 es un caracter qeu note que cuyando lo usabmos
|
||
|
|
// en cunficones "de bajo" nivel como SetChar o StringInit (donde trabajsmo diremate )
|
||
|
|
// con su buffer (no con una api "amigable" += "" o algo asi)
|
||
|
|
// hay que tener cuidado con el \0 dado qeu visualemte se corta el print
|
||
|
|
// (en += "\0") pero la logitud len sigue bien, si lo imrres luego en SetChar parece que el len solo apunta a la parte
|
||
|
|
// antes del \0 parece uqe string intemante no es un mescanis buffer* len si no mas
|
||
|
|
// se guia tambien del \0 pero es raro eso..
|
||
|
|
|
||
|
|
}
|
||
|
|
//+------------------------------------------------------------------+
|
||
|
|
#endif // TSNTABES_SRC_BITS_H_MQH
|