String to int exception

Alexandre via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 15 06:30:35 PDT 2014


Something is wrong between our communication...

I am wanting to do something better to order the bytes, for this 
my code...
https://gist.github.com/bencz/3576dfc8a217a34c05a9

For example, in that case:
injectData(image[0x207], x"30204000");

It's more simple to use something like:
injectData(image[0x207], inverseBytes(0x00402030));


On Tuesday, 15 July 2014 at 13:15:34 UTC, bearophile wrote:
> 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