0
Views
0
Downloads
0
Favorites
DecBinHex
//+------------------------------------------------------------------+
//| DecBinHex.mq4 |
//| Itso |
//| itso@dir.bg |
//+------------------------------------------------------------------+
#property copyright "Itso"
#property link "itso@dir.bg"
#property library
//+------------------------------------------------------------------+
//| My functions |
//+------------------------------------------------------------------+
string DecToBin(int n)
{
string s = "";
while(n != 0)
{
s = CharToStr(n % 2 + '0') + s;
n = n / 2;
}
return(s);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int BinToDec(string s)
{
int p = 0, i;
for(i = 0; i < StringLen(s); i++)
{
p = p*2 + StringGetChar(s,i) - '0';
}
return(p);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string DecToHex(int n)
{
string s = "", c;
while(n != 0)
{
if(n%16 < 10)
c = CharToStr(n % 16 + '0');
else
c = CharToStr(n % 16 + 'A'-10);
s = c + s;
n = n / 16;
}
return(s);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int HexToDec(string s)
{
int p = 0, c, i;
for(i = 0; i < StringLen(s); i++)
{
if((StringGetChar(s, i) >= '0') && (StringGetChar(s, i) <= '9'))
c = StringGetChar(s, i) - '0';
else
if((StringGetChar(s, i) >= 'A') && (StringGetChar(s, i) <= 'F'))
c = StringGetChar(s, i) - 'A' + 10;
else
if((StringGetChar(s, i) >= 'a') && (StringGetChar(s, i) <= 'f'))
c = StringGetChar(s, i) - 'a' + 10;
else
return(-1);
p = p*16 + c;
}
return(p);
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---