what does the '~' mean in python?
i found this BF interpreter in python a while ago.
import sys
#c,i,r,p=0,0,[0]*255,raw_input()
c=0
i=0
p=raw_input()
r=[0]*255
while c<len(p):
m,n,u=p[c],0,r[i]
if m==">":i+=1
if m=="<":i-=1
if m=="+":r[i]+=1
if m=="-":r[i]-=1
if m==".":sys.stdout.write(chr(u))
if m=="[":
if ~u:
while 1:
m=p[c]
if m=="]":n-=1
if m=="[":n+=1
if ~n:break
c+=1
if m=="]":
if u:
while 1:
m=p[c]
if m=="]":n-=1
if m=="[":n+=1
if ~n:break
c-=1
c+=1
and i want to know what it does because i want to make one on my ti 84 (and a PF one)
BF is http://en.wikipedia.org/wiki/Brainfuck and PF is something similar
Bitwise NOT, just like in C.
In two's complement representation, ~n
is equivalent to -n - 1
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With