Sapere il tipo di dato più piccolo in Gambas capace di contenere e rappresentare un numero

Da Gambas-it.org - Wikipedia.

Per sapere il tipo di dato più piccolo in Gambas capace di contenere e rappresentare un numero (sia esso positivo o negativo), si può adottare il seguente codice: [nota 1]

Private Const NUMERO As Long = 21081969   ' Il numero da verificare


Public Sub Main()

 Dim n, t, s As String
 Dim b As Byte

 n = "1"
 t = "BYTE"
 If NUMERO < 0 Then 
   n = "0"
   t = "SHORT"
 Endif 

 Print Bin(NUMERO, 64)
 b = InStr(Bin(NUMERO, 64), n)

 s = "LONG"
 If b > 33 Then s = "INTEGER"
 If b > 49 Then s = "SHORT"
 If (b == 0) Or (b > 56) Then s = t

 Print "\nIn Gambas il numero \e[31m"; CStr(NUMERO); "\e[0m può essere contenuto da un dato di tipo: \e[31m"; s

End


Note

[1] Vedere anche questa pagina: Sapere con le funzioni esterne del API di Glib quanti bit sono necessari per contenere un numero