|
![](/i/fill.gif) |
"JS" <bos### [at] yahoo co uk> wrote in message
news:web.459c36d822a5f346188aeae70@news.povray.org...
> Hi, all.
>
> Maybe I've missed this, but could someone please tell me how I can use HEX
> instead of decimal numbers for constants. I trying to use data to
> construct
> 3D models with hex values without having to convert them to decimal.
>
> Thank you for your time.
>
Hi,
I can't think of anything in POV-Ray that handles hexadecimal numbers.
Someone else may know better, but I'd say you'll have to convert them.
Here's a simple POV-Ray conversion macro that should enable you to use
hexadecimal numbers inline in your SDL.
#macro X2D(Hex)
#local Digits = "0123456789ABCDEF";
#local Hex = strupr(Hex);
#local I = strlen(Hex);
#local Decimal = 0;
#local Factor = 1;
#while (I>0)
#local Character = substr(Hex,I,1);
#local J = 0;
#local Found = 0;
#while (J<strlen(Digits))
#if (strcmp(Character,substr(Digits,J+1,1))=0)
#local Decimal = Decimal + J * Factor;
#local Found = 1;
#end
#local J = J + 1;
#end
#if (!Found) #error concat("\nX2D - Character position ",str(I,3,0),
"of ",Hex," contains an invalid Hex character\n\n") #end
#local Factor = Factor * 16;
#local I = I-1;
#end
Decimal
#end
#declare MyValue = X2D("01F");
#debug concat("\nDecimal Value: ",str(MyValue,10,0),"\n\n")
Hope this helps,
Regards,
Chris B.
Post a reply to this message
|
![](/i/fill.gif) |