|
|
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
>
> > You can try this:
>
> Leave it to you to post a full code example before I even finished typing my
> request :D (He's too fast for me, folks.)
Then perhaps I started before you ;)
> That ought to give me some more interesting material for div and mod as well.
> :)
>
> Thanks for keeping the info flowing - there's always something new to learn.
If you want to try to do something along the way Thorsten suggested, here's some
code to start with:
#version 3.7;
#declare UnsignedInteger = 4091728320; // 0xf3e2d1c0
#debug "\n\n"
#debug str(UnsignedInteger, 0, 0)
#debug "\n"
#declare NoOfBits = ceil(ln(UnsignedInteger)/ln(2));
#declare TheBits = array[NoOfBits];
#declare R = UnsignedInteger;
#for (I, 0, NoOfBits-1)
#declare TheBits[I] = mod(R, 2);
#declare R = div(R, 2);
#end // for
#declare N = 0;
#for (I, NoOfBits-1, 0, -1)
#declare InvertedBit = 1 - TheBits[I];
#declare N = 2*N + InvertedBit;
#end // for
#debug str(N, 0, 0) // 203238975 = 0x0C1D2E3F
#debug "\n\n"
#error "Finished"
If you get to a point where you need to mask away all other bits than the lower
32 your can do this:
#declare N = mod(N, pow(2, 32));
--
Tor Olav
http://subcube.com
https://github.com/t-o-k
Post a reply to this message
|
|