POV-Ray : Newsgroups : povray.advanced-users : write uint32_t : Re: write uint32_t Server Time
18 Oct 2021 12:16:48 EDT (-0400)
  Re: write uint32_t  
From: Tor Olav Kristensen
Date: 29 Mar 2021 16:45:00
Message: <web.60623c1a8cf934b8ae6f04a89db30a9@news.povray.org>
"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

Copyright 2003-2021 Persistence of Vision Raytracer Pty. Ltd.