 |
 |
|
 |
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
in news:60620b36$1@news.povray.org Thorsten wrote:
> You can just compute the two's complement inverse before output, and
> you get what you want
>
Sorry Thorsten, I realy don't understand. Can we do it by example.
I have a number, 4321 and it hast to written to a file as uint_32.
Ingo
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
ingo <ing### [at] tag povray org> wrote:
> The fine documentation states: "Note: Currently, unsigned 32-bit words are
> not supported."
>
> Guess what. I need those.
>
> Is there some trickery with 4 uint8' or 2 uint16le's to get the proper
> bytes in the proper place?
Hi Ingo
You can try this:
#version 3.7;
#declare AnInteger = 4091728320; // 0xf3e2d1c0
#declare R = AnInteger;
#declare Byte_0 = mod(R, 256);
#declare R = div(R, 256);
#declare Byte_1 = mod(R, 256);
#declare R = div(R, 256);
#declare Byte_2 = mod(R, 256);
#declare R = div(R, 256);
#declare Byte_3 = mod(R, 256);
#fopen SomeFile "LitteEndian.bin" write
#write (SomeFile, uint8 Byte_0)
#write (SomeFile, uint8 Byte_1)
#write (SomeFile, uint8 Byte_2)
#write (SomeFile, uint8 Byte_3)
#fclose SomeFile
#fopen SomeFile "BigEndian.bin" write
#write (SomeFile, uint8 Byte_3)
#write (SomeFile, uint8 Byte_2)
#write (SomeFile, uint8 Byte_1)
#write (SomeFile, uint8 Byte_0)
#fclose SomeFile
#error "Finished"
You can upload the resulting files to this web page: https://hexed.it
- and then inspect the results as both big endian and little endian integeres.
--
Tor Olav
http://subcube.com
https://github.com/t-o-k
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
If you get any of that to work, I would like a very small working code snippet
to paste into my collection of Keyword Examples.
Computing complement inverses would be a nice trick to add in as well.
I'm sticking to the stuff I know how to do already, and saving the "need to
learn that" stuff until later/last.
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
in news:web.60620e7f8cf934b8ae6f04a89db30a9@news.povray.org Tor Olav
Kristensen wrote:
>
> #declare AnInteger = 4091728320; // 0xf3e2d1c0
>
> #declare R = AnInteger;
> #declare Byte_0 = mod(R, 256);
> #declare R = div(R, 256);
>
> [.....]
>
Thank you Tor Olav!
Ingo
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmail com> 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.)
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.
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
"Bald Eagle" <cre### [at] netscape net> wrote:
> "Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmail com> 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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 29.03.2021 19:25, ingo wrote:
> in news:60620b36$1@news.povray.org Thorsten wrote:
>
>> You can just compute the two's complement inverse before output, and
>> you get what you want
>>
>
> Sorry Thorsten, I realy don't understand. Can we do it by example.
> I have a number, 4321 and it hast to written to a file as uint_32.
Unsigned is only relevant when dealing with numbers past 2**31, so you
can just write it as signed.
Thorsten
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 29.03.2021 19:40, Bald Eagle wrote:
> If you get any of that to work, I would like a very small working code snippet
> to paste into my collection of Keyword Examples.
>
> Computing complement inverses would be a nice trick to add in as well.
>
> I'm sticking to the stuff I know how to do already, and saving the "need to
> learn that" stuff until later/last.
It should be (untested):
#declare uint32 = function(x) { select(x-2147483648, x, x-4294967296) }
Thorsten
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
in news:6062cd94$1@news.povray.org Thorsten wrote:
> Unsigned is only relevant when dealing with numbers past 2**31, so you
> can just write it as signed.
>
It's a field in a header file describing the data length in it. The
maximum length can be up to 2^32. Hence the unint32 question regardless of
the actual data length.
Thanks Thorsten,
Ingo
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
ingo <ing### [at] tag povray org> wrote:
> in news:60620b36$1@news.povray.org Thorsten wrote:
>
> > You can just compute the two's complement inverse before output, and
> > you get what you want
> >
>
> Sorry Thorsten, I realy don't understand. Can we do it by example.
> I have a number, 4321 and it hast to written to a file as uint_32.
Here's how you can do it with sint32le and sint32be. This does it like Thorsten
indicated in his last post.
#version 3.7;
// #declare UnsignedInteger = 0; // 0x00000000
// #declare UnsignedInteger = 1; // 0x00000001
// #declare UnsignedInteger = pow(2, 31) - 1; // 0x7FFFFFFF
// #declare UnsignedInteger = pow(2, 31); // 0x80000000
// #declare UnsignedInteger = pow(2, 31) + 1; // 0x80000001
// #declare UnsignedInteger = pow(2, 32) - 1; // 0xFFFFFFFF
#declare UnsignedInteger = 4321; // 0x000010E1
// #declare UnsignedInteger = 1059986700; // 0x3F2E1D0C
// #declare UnsignedInteger = 4091728320; // 0xF3E2D1C0
#if (UnsignedInteger < pow(2, 31))
#declare N = UnsignedInteger;
#else
#declare N = UnsignedInteger - pow(2, 32);
#end // if
#debug concat("\n\n", str(N, 0, 0), "\n\n")
#fopen SomeFile "LitteEndian32.bin" write
#write (SomeFile, sint32le N)
#fclose SomeFile
#fopen SomeFile "BigEndian32.bin" write
#write (SomeFile, sint32be N)
#fclose SomeFile
#error "Finished"
--
Tor Olav
http://subcube.com
https://github.com/t-o-k
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |