<div class="gmail_quote">On Thu, Jul 14, 2011 at 12:03 AM, Andrew Wiley <span dir="ltr"><<a href="mailto:wiley.andrew.j@gmail.com">wiley.andrew.j@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div><div></div><div class="h5"><div class="gmail_quote">On Wed, Jul 13, 2011 at 11:59 PM, Jonathan M Davis <span dir="ltr"><<a href="mailto:jmdavisProg@gmx.com" target="_blank">jmdavisProg@gmx.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div></div><div>On Wednesday 13 July 2011 23:37:02 Andrew Wiley wrote:<br>
> Hey, does anyone else thing a function like this belongs in Phobos, and if<br>
> so, where do you think it should go?<br>
><br>
> T ntoh(T)(T val) if (__traits(isArithmetic, T)) {<br>
> version(BigEndian) {<br>
>  return val;<br>
> }<br>
> else version (LittleEndian) {<br>
>  ubyte[] arr = (cast(ubyte*)&val)[0 .. T.sizeof];<br>
> ubyte temp;<br>
> for(int i = 0; i < T.sizeof/2; i++) {<br>
>  temp = arr[i];<br>
> arr[i] = arr[T.sizeof - i - 1];<br>
> arr[T.sizeof - i - 1] = temp;<br>
>  }<br>
> return val;<br>
> }<br>
>  else static assert(0, "Are you sure you're using a computer?");<br>
>  }<br>
><br>
> I was looking for something along these lines in the docs today and couldn't<br>
> find it. It looks like there's a stream in std.stream to do this, but,<br>
> well, I think we've all been pretending std.stream doesn't exist for a<br>
> while now.<br>
<br>
</div></div>core.sys.posix.arpa.inet.d<br>
std.c.windows.winsock.d<font color="#888888"><br></font></blockquote></div><br></div></div><div>Both of those are platform specific, and neither of them is general enough to handle longs.</div></blockquote><div><br></div>

<div>(However, they're also both faster than what I've written because I really don't need a dynamic array for something like this) </div></div><br>