Code: Select all
Function POT(ByVal num As Integer)As ULongInt
Dim i As Integer
Dim resultado As ULongInt
resultado=1
For i=1 To num
resultado=resultado*2
Next
POT=resultado
End Function
Code: Select all
Function POT(ByVal num As Integer)As ULongInt
Dim i As Integer
Dim resultado As ULongInt
resultado=1
For i=1 To num
resultado=resultado*2
Next
POT=resultado
End Function
Code: Select all
Const As ULongInt ULImax = &hFFFFFFFFFFFFFFFF
Sorry, not understand :-(MrSwiss wrote:I don't really understand what exactly you're after.
If it's the maximum value a ULongInt can hold use:Just print it out to get the DEC equivalent.Code: Select all
Const As ULongInt ULImax = &hFFFFFFFFFFFFFFFF
Code: Select all
a = (1 shl x) OR (1 shl y) OR (1 shl z)
Mmmm..... I´m not sure if I could do it this way. The other way was the first I thought. Well, the second, the first was complete it manually (with the help of this: http://www.talkchess.com/forum3/viewtopic.php?t=39053 ) as i did with knights moves (but for bishpos and rooks are too many to do it manually so I thought what I said)! :-Dcaseih wrote:Yeah I'm confused too. Why are you doing exponentiation when you're really just after a bit mask. Just use bit shifting. That's what it's there for and CPUs can do it super efficiently with no math. To be clear, say you want to turn on bits x,y, and z. Instead of multiplying out 2 to the powers of x, y, and z, just do some bitwise operations:Hopefully you get the picture. This is a classic bit mask.Code: Select all
a = (1 shl x) OR (1 shl y) OR (1 shl z)
Code: Select all
'Ataques caballos:
For i=0 To 63
Read AtaquesCaballos(i)
Next
Data 132096,329728,659712,1319424,2638848,5277696,10489856,4202496
Data 33816580,84410376,168886289,337772578,675545156,1351090312,2685403152,1075839008
Data 8657044482,21609056261,43234889994,86469779988,172939559976,345879119952,687463207072,275414786112
Data 2216203387392,5531918402816,11068131838464,22136263676928,44272527353856,88545054707712,175990581010432,70506185244672
Data 567348067172352,1416171111120896,2833441750646784,5666883501293568,11333767002587136,22667534005174272,45053588738670592,18049583422636032
Data 145241105196122112,362539804446949376,725361088165576704,1450722176331153408,2901444352662306816,5802888705324613632,11533718717099671552,4620693356194824192
Data 288234782788157440,576469569871282176,1224997833292120064,2449995666584240128,4899991333168480256,9799982666336960512,1152939783987658752,2305878468463689728
Data 1128098930098176,2257297371824128,4796069720358912,9592139440717824,19184278881435648,38368557762871296,4679521487814656,9077567998918656
'Ataques Alfiles:
'Noreste:
For f=1 To 8
For c=1 To 8
fa=f
ca=c
While (fa<8 And ca<8)
fa=fa+1
ca=ca+1
pivote=DosALa(8*(fa-1)+(ca-1))
AtaquesAlfilesNE(8*(f-1)+(c-1))=AtaquesAlfilesNE(8*(f-1)+(c-1))+pivote
Wend
'Print 8*(f-1)+(c-1),AtaquesAlfilesNE(8*(f-1)+(c-1))
'Sleep
Next
Next
Code: Select all
Dim Shared As Ubyte addmod(0 To 19),addbool(0 To 19) 'lookup array
For z As Integer=0 To 19
addmod(z)=(z Mod 10+48)
ADDbool(z)=(-(10<=z))
Next z
Function plus(_num1 As String,_num2 As String) As String
Var _flag=0,n_=0
Dim As Ubyte addup=Any,addcarry=Any
#macro finish()
answer=Ltrim(answer,"0")
If _flag=1 Then Swap _num2,_num1
Return answer
#endmacro
If Len(_num2)>Len(_num1) Then
Swap _num2,_num1
_flag=1
End If
Var diff=Len(_num1)-Len(_num2)
Var answer="0"+_num1
addcarry=0
For n_=Len(_num1)-1 To diff Step -1
addup=_num2[n_-diff]+_num1[n_]-96
answer[n_+1]=addmod(addup+addcarry)
addcarry=addbool(addup+addcarry)
Next n_
If addcarry=0 Then
finish()
End If
If n_=-1 Then
answer[0]=addcarry+48
finish()
Endif
For n_=n_ To 0 Step -1
addup=_num1[n_]-48
answer[n_+1]=addmod(addup+addcarry)
addcarry=ADDbool(addup+addcarry)
If addcarry=0 Then Exit For
Next n_
answer[0]=addcarry+48
finish()
End Function
Function bigger(num2 As String,num1 As String) As Long
Var lens=Len(num2),lenf=Len(num1)
If Lens>lenf Then Return -1
If Lens<lenf Then Return 0
If NUM2>NUM1 Then Return -1 Else Return 0
End Function
Dim As Ulongint temp
Dim As String s(63)
For i As Long=0 To 63
Read temp
s(i)=Str(temp)
Next
Data 132096,329728,659712,1319424,2638848,5277696,10489856,4202496
Data 33816580,84410376,168886289,337772578,675545156,1351090312,2685403152,1075839008
Data 8657044482,21609056261,43234889994,86469779988,172939559976,345879119952,687463207072,275414786112
Data 2216203387392,5531918402816,11068131838464,22136263676928,44272527353856,88545054707712,175990581010432,70506185244672
Data 567348067172352,1416171111120896,2833441750646784,5666883501293568,11333767002587136,22667534005174272,45053588738670592,18049583422636032
Data 145241105196122112,362539804446949376,725361088165576704,1450722176331153408,2901444352662306816,5802888705324613632,11533718717099671552,4620693356194824192
Data 288234782788157440,576469569871282176,1224997833292120064,2449995666584240128,4899991333168480256,9799982666336960512,1152939783987658752,2305878468463689728
Data 1128098930098176,2257297371824128,4796069720358912,9592139440717824,19184278881435648,38368557762871296,4679521487814656,9077567998918656
For n As Long=0 To 63
Print "s(";n;") = "; s(n)
Next
Print
Dim As String max="18446744073709551615"
Dim As String tot="0"
dim as double check
print "Sum up all the array elements"
print "Sums string";tab(50);"Sums Doubles"
For n As Long=0 To 63
tot=plus(s(n),tot)
check+=val(s(n))
Print tot+Iif(bigger(tot,max)," outside ulongint","");tab(50);check
Next
Print
Print "check all added pairs outside ulongint:"
For n1 As Long=Lbound(s) To Ubound(s)-1
For n2 As Long=n1+1 To Ubound(s)
If bigger(plus(s(n1),s(n2)),max) Then
Print " ";s(n1);" =s(";n1;")"
Print "+";s(n2);" =s(";n2;")"
Print "_________________"
Print plus(s(n1),s(n2))," outside ulongint"
End If
Next
Next
'dim as ulongint z=-1
Sleep
Not sure if I understand what you said, but your comment made me find a far simpler solution:caseih wrote:Yeah I'm confused too. Why are you doing exponentiation when you're really just after a bit mask. Just use bit shifting. That's what it's there for and CPUs can do it super efficiently with no math. To be clear, say you want to turn on bits x,y, and z. Instead of multiplying out 2 to the powers of x, y, and z, just do some bitwise operations:Hopefully you get the picture. This is a classic bit mask.Code: Select all
a = (1 shl x) OR (1 shl y) OR (1 shl z)
Code: Select all
'Ataques Alfiles:
'Noreste:
For f=1 To 8
For c=1 To 8
fa=f
ca=c
While (fa<8 And ca<8)
fa=fa+1
ca=ca+1
AtaquesAlfilesNE(8*(f-1)+(c-1))=AtaquesAlfilesNE(8*(f-1)+(c-1)) Or BitSet(AtaquesAlfilesNE(8*(f-1)+(c-1)),(8*(fa-1)+(ca-1)))
Wend
'Print 8*(f-1)+(c-1),AtaquesAlfilesNE(8*(f-1)+(c-1))
'Sleep
Next
Next
Code: Select all
Dim a As ULongInt
a=18049651735527936
Print a+2^0
Sleep
Code: Select all
Dim a As ULongInt
a = 18049651735527936
a = a + 2 ^ 0 'conversion from and to ULongInt happens here
Print a
Sleep
Code: Select all
Dim a As ULongInt
a = 18049651735527936
a = a + cast(ULongInt, 2 ^ 0)
Print a
Sleep
Fine, but not enough information about the layout.A 64 bits word is used as a chessboard.
bit 0 is A1MrSwiss wrote:Fine, but not enough information about the layout.A 64 bits word is used as a chessboard.
If I assume for instance: field (on chess board) A1 is represented in bit 0 (lowermost bit) then:
is bit 1 representative for A2, or B1? e.t.c. while you might know those things, others here don't ...
Is my first assumption correct or not?
Thanks badidea.badidea wrote:Don't use ^ with integers. The ^ operator takes 2 doubles as inputs and returns a double. When used with integers, automatic conversion to and from doubles is done. Example:Prints: 1.804965173552794e+16Code: Select all
Dim a As ULongInt a=18049651735527936 Print a+2^0 Sleep
Interestingly fbc 32-bit behaves different fbc 64-bit. For this code:linux fbc 32-bit --> 18049651735527937Code: Select all
Dim a As ULongInt a = 18049651735527936 a = a + 2 ^ 0 'conversion from and to ULongInt happens here Print a Sleep
linux fbc 64-bit --> 18049651735527936
OK with with this code:Code: Select all
Dim a As ULongInt a = 18049651735527936 a = a + cast(ULongInt, 2 ^ 0) Print a Sleep