Code: Select all
Sub ShowBits32( p as any ptr, Newline As boolean = true)
'' init gfx or u will see wrong color
'' use ScreenRes x,y, 32
Dim As ulong I, AryFG(3), AryBG(3)
var oldcol = color()
AryFG(0) = RGB(200,200,200)
AryFG(1) = RGB(255,0,0)
AryFG(2) = RGB(0,255,0)
AryFG(3) = RGB(0,96,255)
AryBG(0) = RGB(100,100,100)
AryBG(1) = RGB(127,0,0)
AryBG(2) = RGB(0,127,0)
AryBG(3) = RGB(0,0,127)
dim as ulong ptr v = p
For I = 0 To 3
Color AryFG(I), AryBG(I)
print bin(*v shr (24 - i*8), 8);
Next
If Newline Then Print
color oldcol
End Sub
sub ShowBits64(p as any ptr, Newline As boolean = true)
showbits32 p+4, false
ShowBits32 p, newline
END SUB
type sng_x2
as Single a,b
END TYPE
type ulong_x2
as ULong a,b
END TYPE
union Union64
as sng_x2 s
as ulong_x2 u
as double d
as ULongInt uu
END UNION
screenres 800,600, 32
dim as Union64 n
for i as long = 0 to 23
n.s.a = rnd
n.u.b = i shl 8
n.uu or= culngint(1) shl 34
showbits64 @n
next
sleep
Code: Select all
'
' Simple RNG by Thorham - macro adaptation by dafhi - 2014 Dec 28
' http://www.freebasic.net/forum/viewtopic.php?f=7&t=16044
'
Dim Shared As long t_rng_z, t_rng_d
#Macro tRNG()
Asm
mov ecx, [t_rng_z]
mov eax, [t_rng_d]
rol eax,7
Add eax,ecx
mov [t_rng_d],eax
Add ecx, &H11111111
mov [t_rng_z], ecx
End Asm
#EndMacro
' ---- rng end ---- '
Sub ShowBits32( ByVal pAny32 As any ptr, ByVal NoNewline As Integer = 0)
Dim As ulong strPos, bitPos, AryFG(3), AryBG(3),I,J
dim as long ptr p32 = pAny32
Dim str_ As String * 8
AryFG(0) = RGB(200,200,200)
AryFG(1) = RGB(255,0,0)
AryFG(2) = RGB(0,255,0)
AryFG(3) = RGB(0,32,255)
AryBG(0) = RGB(100,100,100)
AryBG(1) = RGB(127,0,0)
AryBG(2) = RGB(0,127,0)
AryBG(3) = RGB(0,0,86)
For I = 0 To 3
Color AryFG(I), AryBG(I)
For J = 0 To 7
bitPos = (3 - I) Shl 3 + J
strPos = 7 - J
If bit(*p32, bitPos) Then str_[strPos] = 49 Else str_[strPos] = 48
Next
Print str_;
Next
If Not NoNewline Then Print
End Sub
sub SeedRNG_and_ShowSomething(seed_a as long=0, seed_b as long=0)
t_rng_z = seed_a
t_rng_d = seed_b
color rgb(200,200,200), rgb(0,0,0)
? "seeds "; t_rng_z; " "; t_rng_d
?
for i as integer = 1 to 50
tRNG()
ShowBits32 @t_rng_z
next: ?
end sub
Sub Main
screenres 640, 480, 32
randomize
SeedRNG_and_ShowSomething Rnd * &HFffFFff, Rnd * &HFffFFff
end sub
Main
sleep