String to int exception
Alexandre via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jul 15 04:56:11 PDT 2014
Hi :)
I made this function to inverse the bytes in intger or T
(possible) type...
int reverseBytes(T)(T val)
{
int retVal = 0;
static if(is(T == string))
retVal = to!int(val);
return (retVal & 0x000000FF) << 24 |
(retVal & 0x0000FF00) << 8 |
(retVal & 0x00FF0000) >> 8 |
(retVal & 0xFF000000) >> 24;
}
//...
writefln("%x", reverseBytes(x"00402030"));
//...
When I execute this program, I got this exception:
std.conv.ConvException at C:\D\dmd2\src\phobos\std\conv.d(1968):
Unexpected '@' when converting from type string to type int
More information about the Digitalmars-d-learn
mailing list