-4

plz , i need help about how can i get the equivalent code in c# to any macro code in c/c++ as this macro .

#define BYTESWAP16(x)                   \
    ((((x) >> 8) & 0x00FF) | (((x) << 8) & 0xFF00))
#define BYTESWAP32(x)                   \
    ((((x) >> 24) & 0x000000FF) | (((x) >> 8) & 0x0000FF00) | \
     (((x) << 8) & 0x00FF0000) | (((x) << 24) & 0xFF000000))
#define ntohs(x)                        BYTESWAP16(x)
#define htons(x)                        BYTESWAP16(x)
#define ntohl(x)                        BYTESWAP32(x)
#define htonl(x)                        BYTESWAP32(x)

2 Answers2

6

You can use IPAddress.HostToNetworkOrder and IPAddress.NetworkToHostOrder to perform these operations. These are built into the framework.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
0

You may define a sealed abstract class with static methods that will do the same as your macros do.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335