#include "crt.bi" #include "vbcompat.bi" #define ArgC ((*__p___argc())-1) #ifndef False Const False=0, True=Not False #endif #Undef GoTo 'jojo is right, thx ;-)) '+------------------------------------------------------------------------------------------+ '| Header: Evaluating parameters | '| DisplayCheck:|Il1 are Alt-0124, Big i, small L, One ߎę֚񱸩 | Const Author="BitWise-e.bas v1.1 2012 by ytwinky, MD"' | '| (Shortcuts: none) | '| Purpose: Playground for BitOperations | '|Tested with the latest FB and FBEdit" | '+------------------------------------------------------------------------------------------+ Const Esc=!"\27", Lf=!"\n", F1=!"\255;", light=8, red=4 Function ReadKey(s As String="") As String If s<>"" Then Print s; s="" Do s=UCase(InKey) Sleep(1) Loop Until s<>"" Return s End Function Function GetVal(byVal Which As String, byVal Value As Integer) As Integer Var w="" Print "New contents for " &Which &":"; Input "", w If w<>"" Then Return ValInt(w) Return Value End Function Function MenuChar(byVal s As String, byVal First As Integer=1, byVal nFG As Integer=light+red)As String Var cFG=LoWord(Color) If First<>1 Then Print Left(s, First-1); Color nFG Print Chr(s[First-1]); Color cFG Return Mid(s, First+1) End Function Function ShowVar(byVal Which As Integer) As String Var FInt=Str(Which) FInt=String(11-Len(FInt), " ") &FInt Return FInt &" " & Bin(Which, 32) &" " & Hex(Which, 8) &" " & Oct(Which, 12) End Function Var m="", n="", i=0, fun="SHR", b=18687, v=8, r=0 Cls Print Author &Lf &"32-Bit Integer(+|-)" &Space(18) &"Bin" &Space(18) &"Hex" &Space(7) &"Oct" Do For i=0 To 6 Locate 9+i, 1 Print String(79, " ") 'clear input-lines.. Next Locate 3, 1 Print MenuChar(" Base:", 6) &ShowVar(b) Print MenuChar(" Value:", 5) &ShowVar(v) Select Case fun Case "AND" : r=b AND v Case "ANDALSO" : r=b ANDALSO v Case "OR" : r=b OR v Case "ORELSE" : r=b ORELSE v Case "XOR" : r=b XOR v Case "EQV" : r=b EQV v Case "IMP" : r=b IMP v Case "SHL" : r=b SHL v Case "SHR" : r=b SHR v End Select Print " Result:" &ShowVar(r) Print " Current:Result=Base " &fun &" Value " Print "Functions:"; MenuChar("NOT "); MenuChar("AND "); MenuChar("ANDALSO ", 3); MenuChar("OR "); MenuChar("ORELSE ", 5); Print MenuChar("XOR ");MenuChar("EQV "); MenuChar("IMP "); MenuChar("SHL ", 3); MenuChar("SHR ", 3); Print MenuChar("Toggle "); MenuChar("Help(F1)");!"\nSelect(Esc ends..): \b\b"; Do m=ReadKey() Loop Until Instr("BVNAOXEILRTHDS" &F1 &Esc, m) If m=F1 Then m="F1" Print m Select Case m Case "N" Print MenuChar("NOT base or NOT ", 5); MenuChar("value:"); Do n=ReadKey() Loop Until Instr("BV" &Esc, n) If n="B" Then b=Not b If n="V" Then v=Not v Case "A" : fun="AND" Case "D" : fun="ANDALSO" Case "O" : fun="OR" Case "S" : fun="ORELSE" Case "X" : fun="XOR" Case "E" : fun="EQV" Case "I" : fun="IMP" Case "R" : fun="SHR" Case "L" : fun="SHL" Case "B" : b=GetVal("base", b) Case "V" : v=GetVal("value", v) Case "T" Input "Which Bit to toggle in base? BitNo.:", i If i>=0 And i<32 Then b Xor=2^i Else Print "Do You really know what You're doin'?^^"; GetKey EndIf Case "H", "F1" n=!"This is a simple program for playing with bit-operations\n" n &=!"Just enter base, value and select the desired function, that's it..\n" n &=!"The selected function is displayed on the screen if it concerns both numbers.\n" n &=!"Allowed (menu-)chars are red, so You can easily see, what is possible.\n" n &=!"Beware: Input per &H.., &B.. and &O.. is allowed too..\n" n &=!"While in Input-Mode: pressing Enter doesn't change anything ;-))\n" Print n &!"Arguments from the commandline are not supported!"; GetKey End Select Loop Until m=Esc End