Harrierfalcon’s z80 Programmer
My games, code snippets, etc.

Archive for the 'Code Snippets' Category

Decimal to Binary!

January 25, 2007

Yes, in one line you can convert any size decimal to binary.
seq(int(2fPart(N/2^Z)),Z,B,1,-1t
N is the number to be converted, while B is the number of bits.

A small math prog…

January 13, 2007

Here’s a small program that will find all whole factors of a number. The bigger the number, the longer it takes, though…
:ClrHome
:Repeat Z and Z≤999 not(fPart(Z
:Input “Number? “,Z
:End
:ClrHome
:Output(8,1,”Calculating…
elVar L1Z→dim(L1
elVar L2Ans→dim(L2
:For(θ,1,Z
:Z/θ
:If not(fPart(Ans
:Then
:Ans→L1(θ
:θ→L2(θ
:End
:End
:If not(max(L1
:Then
:ClrHome
isp “It’s prime!
:Stop
:End
:Output(1,1,Z
:Output(2,1,”divided by
:Output(4,1,”is
:For(θ,1,Z
:”
:Output(3,1,Ans
:Output(5,1,Ans
:Output(8,1,”Calculating
:If L2(θ
:Then
:Output(3,1,L2(θ
:Output(5,1,L1(θ
:Output(8,1,”Press Enter
ause
:End
:End
:ClrHome
elVar L1DelVar L2Output(1,1,”
Obviously there are some optimizations, but [...]