View Full Version : binary 128bit and DLL
Edcronos
28-12-2016, 23:48
Hello, excuse me for using a translator, my English is zero.
I like to play with the vba of excel, and already I have the thinbasic to some time but I never used it
I would like to know if you have binary type comparators with 128bit capacity and bits counting,
like that
Function Bit_Count(ByVal number As Long) As Long
Dim Aa As Long
Do While number
number = number And (number - 1)
Aa = Aa + 1
Loop
Bit_Count = Aa
End Function
Function Bit_AND_Bit(ByVal Bit1 As Long, ByVal Bit2 As Long) As Long
Bit_AND_Bit = Bit1 And Bit2
End Function
Function Bit_OR_Bit(ByVal Bit1 As Long, ByVal Bit2 As Long) As Long
Bit_OR_Bit = Bit1 Or Bit2
End Function
Function Bit_XOR_Bit(ByVal Bit1 As Long, ByVal Bit2 As Long) As Long
Bit_XOR_Bit = Bit1 Xor Bit2
End Function
And create variables at runtime, or just using dictionaries to define something like this.
And if it's possible to mount a DLL with the thinbasic
I tried other languages, but I could not get rid of the "{}" and the need to ";" At the end of each line, it's annoying
I like to set up functions with cascading ties and comparators and I'm kind of addicted to spaghetti
See you later and success.
Eduardo.
ola, desculpe-me por utilizar tradutor, meu ingles é zero
eu gosto de brincar com o vba do excel, e já tenho o thinbasic a algum tempo mas nunca o usei
gostaria de saber se tem comparadores lógicos tipo binário com capacidade de 128bit e Bits counting,
e criar variáveis em tempo de execução , ou apenas usando dicionários para definir algo parecido
tipo assim
e se é possível montar uma DLL com o thinbasic
tentei outras linguagens, mas não consegui me abtuar com os "{ }" e com a necessidade de ";" no final de cada linha , é algo irritante
gosto de montar funções com laços em cascata e comparadores e sou meio viciado em espaguete
até mais e sucesso
ErosOlmi
29-12-2016, 13:12
Ciao Eduardo,
I too hate {} and ; and I suppose we are not alone :D
thinBasic has bitwise operators ANDB, ORB, XOR.
It has also some other functions working on bit like:
left and right bit shifting << and >>
BIT and BIT_GET used to get a particular bit in a LONG variable
BIT_RESET to set to zero a specific bit
BIT_SET to to set to 1 a specific bit
BIT_TOGGLE to toggles a specific bit
All those functions are described in thinBasic Help
You VBA example in thinBasic is very similar, you have to just change "number" to something like "lnumber" (in thinBasic number is a primitive data type, an alias for Extended numeric) and use ANDB and ORB for bit operations:
Function Bit_Count(ByVal lnumber As Long) As Long
Dim Aa As Long
Do While lnumber
lnumber = andb(lnumber, (lnumber - 1))
Aa = Aa + 1
Loop
Bit_Count = Aa
End Function
Function Bit_AND_Bit(ByVal Bit1 As Long, ByVal Bit2 As Long) As Long
Bit_AND_Bit = andb(Bit1, Bit2)
End Function
Function Bit_OR_Bit(ByVal Bit1 As Long, ByVal Bit2 As Long) As Long
Bit_OR_Bit = orb(Bit1, Bit2)
End Function
Function Bit_XOR_Bit(ByVal Bit1 As Long, ByVal Bit2 As Long) As Long
Bit_XOR_Bit = Bit1 Xor Bit2
End Function
If you can give us a complete example on how you think to use such functions and a result example I can see if thinBasic can do the job you need.
Ciao
Eros
Edcronos
29-12-2016, 21:33
Google translation**
Hello
thanks for listening
Although I was not a gambler, I was involved in the study of lotteries "only in the study, I do not have money to bet"
Bitwise operators are great for filtering and comparisons, if you have many other uses
kind,
Here in Brazil we have a lottery that is, from 1 to 25, and has to choose 15 dozen, in which case the 32bit works
Of course, it is not necessary to say how operators would be used for such a case when one speaks of billions of interactions
Had even mounted some functions to assist as test,
as
Function resutToLong(rang As Range, Optional valmax As Long) As Double
arrayval = rang.Value2
l1 = UBound(arrayval, 1)
c1 = UBound(arrayval, 2)
Dim arbit As Double
If valmax = 0 Then
For c = 1 To c1
If valmax < arrayval(1, c) Then valmax = arrayval(1, c)
Next
End If
ReDim arbit0(1 To valmax) As Long
For c = 1 To c1
arbit0(arrayval(1, c)) = 1
Next
For c = 0 To valmax - 1
arbit = arbit + arbit0(valmax - c) * (2 ^ c)
Next
resutToLong = arbit
End Function
Function bintoresut2(bitLong As Double, valmax As Long)
Dim resut As String
bin = Dec2Bin(bitLong, valmax)
For c = 1 To valmax
If Mid(bin, c, 1) = 1 Then resut = resut & "," & c
Next
bintoresut2 = resut
End Function
Sub sdfaf()
MsgBox bintoresut2(5090991 Xor 8238286, 25)
End Sub
'esse peguei por aí
Function Dec2Bin(ByVal DecimalIn As Variant, Optional NumberOfBits As Variant) As String
Dec2Bin = ""
DecimalIn = Int(CDec(DecimalIn))
Do While DecimalIn <> 0
Dec2Bin = Format$(DecimalIn - 2 * Int(DecimalIn / 2)) & Dec2Bin
DecimalIn = Int(DecimalIn / 2)
Loop
If Not IsMissing(NumberOfBits) Then
If Len(Dec2Bin) > NumberOfBits Then
Dec2Bin = "Error - Number exceeds specified bit size"
Else
Dec2Bin = Right$(String$(NumberOfBits, "0") & Dec2Bin, NumberOfBits)
End If
End If
End Function
But I do not like to study this lottery, and I like to put things together that work for anybody, so I dropped it for a while
We have lotteries ranging from 1 to 100, then only with operators capable of using 128bit
I know that processors already have this capability and 128bit countbit some video cards already provide instructions
Https://msdn.microsoft.com/en-us/library/8ayabe4k(v=vs.90).aspx
Until I found assembly codes embedded in c ++ functions, but I'm a bit slow to pick up the thing
In a way they are just things I enjoy playing, as long as it does not bring stress
It should be easy to carry my codes, for which I practically use only "for next, if then and arrays and a few GOTOs, sometimes some gosub when there are many loops lined up, then I remove them
Edcronos
30-12-2016, 06:02
Hello
After much reading, I found the help part of the functions
As far as thinbasic is concerned, I think I can
But I did not find goto or gosub, I know there is a public hatred for these jump commands
But I'm not too smart to ride the things I want without it
For l = LxO To 1 Step -1
If ResulFolm(l, 1) <> 2 Then
For C2 = c2x To Cfco
v = Comand(C2)
For c = Cid To Cfd
dd = Array_valor(l, c)
Call Convert_tipo(dd, Tipo, v)
If v = dd Then GoTo pula_Ev
Next
ResulFolm(l, 1) = 2 'false
GoTo pula_Ef
pula_Ev:
Next
ResulFolm(l, 1) = 1 'True
End If
pula_Ef:
Next
Function Forma_Lista(lista As Variant, ByVal linha As Long) As Variant
Dim C As Long, tem As Boolean, Llt As Long, l As Long
Llt = UBound(lista, 1)
l = 20
Le_Lista:
cis = Split(lista(linha, 1), ";")
tem = False
For C = 0 To UBound(cis)
testnovo:
If IsNumeric(cis(C)) Then
D = Split(lista(cis(C), 1), ";")
If UBound(D) > 0 Then
' e = cis(C)
cis(C) = lista(cis(C), 1)
D = Split(cis(C), ";")
' lista(e, 1) = ""
If UBound(D) > 0 Then tem = True
Else
cis(C) = D(0)
GoTo testnovo
End If
End If
' Cells(l, 20).Value2 = Join(cis, ";")
l = l + 1
If l > 1000 Then End
' Debug.Print Join(cis, ";")
Next
If tem Then linha = Llt: lista(linha, 1) = Join(cis, ";"): GoTo Le_Lista
Forma_Lista = cis
End Function
The functions posted earlier are to transform combinations into decimal and decimal in combination
1,2,25> 25165825
25165825>1,2,25
So comparisons can be made without the loops on top of each value
I also have to value csn
Function cobinaçãoCSN(combinação As Range, valor_max)
If IsArray(combinação) Then
arr = combinação.Value2
c = UBound(arr, 2)
If UBound(arr, 1) > 1 Then cobinaçãoCSN = "apenas uma linha por combinação": Exit Function
Dim i As Long
Dim b As Double, dd As Double
b = 1
For i = 0 To c - 1
b = b * (valor_max - i) / (c - i)
Next
dd = b
c3 = c
For cc = 1 To c3
n = valor_max - arr(1, cc)
b = 1
For i = 0 To c - 1
b = b * (n - i) / (c - i)
Next
c = c - 1
dd = dd - b
Next
cobinaçãoCSN = dd
End If
End Function
to use in excel
= cobinaçãoCSN(G13: I13; 100)
= cobinaçãoCSN(combination range 1 line only, maximum value)
I also have for the csn to combine, despite having to put error handling
Can you tell me if there is any function that allows variables to be used by the string?
varAux="Variable" & "name"
stringVAR(varAux)=10
var2=stringVAR(varAux)
Eduardo
Petr Schreiber
31-12-2016, 19:18
Hi Eduardo,
variable names by string sound like a case for dictionary.
uses "console", "dictionary"
dim values as new cDictionary(1024) ' -- Pre-allocated storage for 1024 named values, but you can have more
string key = "My" + "Value"
values.Add(key, 5) ' -- Sets initial value
values.Add(key, 500) ' -- Overrides 5 to 500
values.Add("YourValue", 42)
printl key + " = " + values.Find(key)
printl "YourValue = " + values.Find("YourValue")
waitkey
Petr
Edcronos
31-12-2016, 23:00
Happy New Year to all.
Hi Petr
I imagined that it would not,
I already tried to mount a function to use the variable pointer
But I think because of the scope does not work, would have to know is arranged this.
And I'm just a curious
I only mount small functions that have many loops and checks, so
Using pointers or dictionaries within one's own codes would not
Had talked about "thinBasic help Online"
Has to stay as a menu, not sub menu of the forum, for beginners and those who visit the page
It took me a long time to find
I believe that for those who visit and use translators it seems that it is to ask for help from someone
It could be something like
"ThinBasic Manual"
"ThinBasic Functions and Instructions"
"ThinBasic tutorial"
Eduardo
Feliz ano novo para todos
oi Petr
imaginei que não teria,
já tentei montar uma função para usar o ponteiro da variavel
mas creio que por causa do escopo não funciona, teria que saber é organizado isso.
e tbm sou apenas um curioso
eu só monto pequenas funções que tem muitos loops e verificações, então
usar ponteiros ou dicionários dentro dos proprios códigos não traria benefícios
tinha falado sobre "thinBasic help Online"
tem que ficar como um menu, e não sub menu do forum, para os iniciantes e os que visitam a pagina
levei um tempão para achar
creio que para os que visitam e usam tradutores fica parecendo que é para pedir ajuda de alguem
podia ser algo como
thinBasic Manual
"thinBasic Funções e instruções"
thinBasic tutorial
Edcronos
11-01-2017, 00:49
In PHP there is a type of dynamic variable
Is it a camouflaged dictionary?
//campos do formulario
//form fields
$campos_formulario = array("nome", "email", "ddd", "telefone");
//gera as variaveis dinamicamente
//generates variables dynamically
foreach($campos_formulario as $campo){
$$campo = $_POST[$campo];
}
A feature of this is very useful
Is it difficult to implement?
Petr Schreiber
15-01-2017, 23:48
Eduardo,
my apologies, but I am not sure I understand.
What do you find problematic regarding the dictionary module please? If I understand correctly, it should do the same for you.
What you are requesting is a syntactic sugar. Would be possible to do, but I wonder why do you need 1:1 syntax with PHP?
Instead of:
x = variable["key"]
you use this in TB:
x = variable.Find("key")
Petr
Edcronos
16-01-2017, 01:14
I'm sorry
Are two different variants although I mistakenly put as a single question
In the case of variable variables of php a new variable is created from the strig value of that first variable
Even arrays it is possible to increase
Being very useful for working with tables, or chained values
I do not know if with the thinbasic dictionary it is possible to implement an array of values with a single key
I just managed to get the key to a new function that works with the array of values that in turn plays into the idice of several other arrays
me desculpe
são duas variantes diferentes apesar de eu erroneamente colocar como uma só pergunta
no caso das variaveis variaveis do php uma nova variavel é criada a parti do valor strig daquela primeira variavel
até mesmo matrizes é possivel incrementar
sendo muito util para trabalhar com tabelas, ou valores encadeados
não sei se com o dicionario do thinbasic é possivel implrementar uma matriz de valores com uma unica chave
eu somente consegui levando a chave pra uma nova função que trabalha com a matriz de valores que por sua vez joga para o idice de varias outras matrizes
Petr Schreiber
22-01-2017, 17:44
Hi Edcronos,
the thinBasic dictionary uses string,string key,value pairs. Thats how it is designed.
But that does not mean you cannot store array, but sure it implies a bit more work.
One of the possible approaches:
uses "console", "dictionary"
dword myDict = dictionary_create(1024) ' -- Preallocated for 1024 items, but more can be specified
dictionary_add(myDict, "values", "uno,dos,tres,quatro")
string values()
parse(dictionary_find(myDict, "values"), values, ",")
long i
for i = 1 to countOf(values)
printl values(i)
next
waitkey
...and here version for dictionary object:
uses "console", "dictionary"
dim myDict as new cDictionary(1024) ' -- Preallocated for 1024 items, but more can be specified
myDict.add("values", "uno,dos,tres,quatro")
string values()
parse(myDict.Find("values"), values, ",")
long i
for i = 1 to countOf(values)
printl values(i)
next
waitkey
Petr