POV-Ray : Newsgroups : povray.advanced-users : Bitwise AND : Re: Bitwise AND Server Time
28 Jul 2024 20:31:52 EDT (-0400)
  Re: Bitwise AND  
From: Mark Weyer
Date: 5 Apr 2004 05:36:20
Message: <407128A0.90405@informatik.uni-freiburg.de>
> Is it possible to do a Bitwise AND in SDL?

Yes, but not directly. Also note, that, as Warp pointed out, pov numbers
are floating point, so you might lose some bits if you use too many.

Untested suggestion:

// to extract bit K of N:

#macro Bit(K,N)
   ((floor(N/pow(2,K))) mod 2)
#end

// bitwise operations with K bits

#macro Not(N,K)
   pow(2,K)-1-N
#end

#macro Nand(N,M,K)
   #local I=0;
   #local R=0;
   #while (I<K)
     #local R = R+(1-Bit(I,N)*Bit(I,M))*pow(2,I);
     #local I = I+1;
   #end
   (R)
#end

#macro And(N,M,K)
   Not(Nand(N,M,K),K)
#end

#macro Or(N,M,K)
   Nand(Not(N,K),Not(M,K),K)
#end

#macro Xor(N,M,K)
   And(Or(N,M,K),Nand(N,M,K),K)
#end


-- 
merge{#local i=-11;#while(i<11)#local
i=i+.1;sphere{<i*(i*i*(.05-i*i*(4e-7*i*i+3e-4))-3)10*sin(i)30>.5}#end
pigment{rgbt 1}interior{media{emission x}}hollow}//  Mark Weyer


Post a reply to this message

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