String to int exception

bearophile via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 15 06:15:33 PDT 2014


Alexandre:

> Thanks, but, when I convert I recive a 'c' in the front of my 
> number...

This shows it inverts all bits, not just the four byte positions. 
I don't understand:


import core.bitop: bitswap;

uint reverseBytes(in uint val) pure nothrow @safe @nogc {
     return val.bitswap;
}

void main() {
     import std.stdio;

     immutable uint x = 0x_00_40_20_30U;
     immutable uint y = x.reverseBytes;
     writefln("%08x", x);
     writefln("%032b", x);
     writefln("%08x", y);
     writefln("%032b", y);
}


Bye,
bearophile


More information about the Digitalmars-d-learn mailing list