MathSwap

ushort 유형의 값에서 바이트 순으로 변경.

ushort  MathSwap(
   ushort  value      // 값
   );

Parameter

value

[in]  바이트 순서를 변경하는 값.

반환값

역 바이트 순서의 ushort 값.

MathSwap

uint 유형 값에서 바이트 순서 변경.

uint  MathSwap(
   uint   value      // 값
   );

Parameter

value

[in]  바이트 순서를 변경하는 값.

반환값

역 바이트 순서로의 uint 값.

MathSwap

ulong 유형 값에서 바이트 순서 변경.

ulong  MathSwap(
   ulong  value      // 값
   );

Parameter

value

[in]  바이트 순서를 변경하는 값.

반환값

역 바이트 순서의 ulong 값.

 

Example:

#property script_show_inputs
 
input ulong  InpLongValue  =  1;    // Enter any ulong value here
input uint   InpIntValue   =  2;    // Enter any uint value here
input ushort InpShortValue =  3;    // Enter any ushort value here
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
 
//--- print the values entered and converted by MathSwap() in decimal and binary representation in the journal
   Print(ValueDescription(InpLongValue));
   Print(ValueDescription(InpIntValue));
   Print(ValueDescription(InpShortValue));
   /*
   result:
   ulong value1
   ulong value72057594037927936 using MathSwap()
   binary ulong value0000000000000000000000000000000000000000000000000000000000000001
   binary ulong value0000000100000000000000000000000000000000000000000000000000000000 using MathSwap()
   
   uint value2
   uint value33554432 using MathSwap()
   binary uint value00000000000000000000000000000010
   binary uint value00000010000000000000000000000000 using MathSwap()
   
   ushort value3
   ushort value768 using MathSwap()
   binary ushort value0000000000000011
   binary ushort value0000001100000000 using MathSwap()
   */
  }
//+------------------------------------------------------------------+
//| Return the text describing the variable values                   |
//+------------------------------------------------------------------+
template <typename T>
string ValueDescription(T x)
  {
   int    num_bits   = sizeof(T)*8;
   string type_name  = typename(T);
   string bin_x      = NumberToBinaryString(x);
   string bin_swap_x = NumberToBinaryString(MathSwap(x));
   return(StringFormat("%s value: %lld\n%s value: %lld using MathSwap()\nbinary %s value: %0*s\nbinary %s value: %0*s using MathSwap()\n"type_namextype_nameMathSwap(x), type_namenum_bitsbin_xtype_namenum_bitsbin_swap_x));
  }
//+------------------------------------------------------------------+
//| Return the binary representation of a number as a string         |
//+------------------------------------------------------------------+
template <typename T>
string NumberToBinaryString(T x)
  {
   string res  = "";
   int    i    = -1;
   uchar  size = sizeof(T)*8-1;
   ulong  mask = (ulong)1<<size;
   while(!((x<<++i)& mask));
   for(; i <=sizei++)
      res += !((x<<i)& mask) ? "0" : "1";
   return res;
  }

참고 항목

Network functions, SocketRead, SocketSend, SocketTlsRead, SocketTlsReadAvailable, SocketTlsSend