Feroc1ty
2011-02-02 15:58:31
Does anyone have a simba function to convert int to binary and binary to int?
2011-02-02 15:58:31
2011-02-02 16:52:01
function HexToStr(Hex : String) : String;
var
I, X, L, H : Integer;
sArr, hArr : TStringArray;
begin
Result := '';
sArr := [' ', '!', '"', '#', '$', '%', '&', '''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~'];
hArr := ['20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '2A', '2B', '2C', '2D', '2E', '2F', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '3A', '3B', '3C', '3D', '3E', '3F', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '4A', '4B', '4C', '4D', '4E', '4F', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '5A', '5B', '5C', '5D', '5E', '5F', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '6A', '6B', '6C', '6D', '6E', '6F', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '7A', '7B', '7C', '7D', '7E'];
L := Length(Hex);
H := High(hArr);
for I := 0 to L do
if I mod 2 <> 0 then
for X := 0 to H do
if Hex[I] + Hex[I+1] = hArr[X] then
Result := Result + sArr[X];
end;
function StrToHex(Str : String) : String;
var
I, X, L, ArrH : Integer;
sArr, hArr : array of String;
begin
Result := '';
sArr := [' ', '!', '"', '#', '$', '%', '&', '''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~'];
hArr := ['20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '2A', '2B', '2C', '2D', '2E', '2F', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '3A', '3B', '3C', '3D', '3E', '3F', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '4A', '4B', '4C', '4D', '4E', '4F', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '5A', '5B', '5C', '5D', '5E', '5F', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '6A', '6B', '6C', '6D', '6E', '6F', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '7A', '7B', '7C', '7D', '7E'];
L := Length(Str);
ArrH := High(sArr);
for I := 1 to L do
for X := 0 to ArrH do
if Str[I] = sArr[X] then
Result := Result + hArr[X];
end;
function BinaryToHex(Bin : String) : String;
var
I, L : Integer;
begin
Result := '';
L := Length(Bin);
for I := 1 to L do
if I mod 4 = 1 then
case Bin[I] + Bin[I+1] + Bin[I+2] + Bin[I+3] of
'0000': Result := Result + '0';
'0001': Result := Result + '1';
'0010': Result := Result + '2';
'0011': Result := Result + '3';
'0100': Result := Result + '4';
'0101': Result := Result + '5';
'0110': Result := Result + '6';
'0111': Result := Result + '7';
'1000': Result := Result + '8';
'1001': Result := Result + '9';
'1010': Result := Result + 'A';
'1011': Result := Result + 'B';
'1100': Result := Result + 'C';
'1101': Result := Result + 'D';
'1110': Result := Result + 'E';
'1111': Result := Result + 'F';
end;
end;
function HexToBinary(Hex : String) : String;
var
I, L : Integer;
begin
Result := '';
L := Length(Hex);
for I := 1 to L do
case Hex[I] of
'0': Result := Result + '0000';
'1': Result := Result + '0001';
'2': Result := Result + '0010';
'3': Result := Result + '0011';
'4': Result := Result + '0100';
'5': Result := Result + '0101';
'6': Result := Result + '0110';
'7': Result := Result + '0111';
'8': Result := Result + '1000';
'9': Result := Result + '1001';
'A': Result := Result + '1010';
'B': Result := Result + '1011';
'C': Result := Result + '1100';
'D': Result := Result + '1101';
'E': Result := Result + '1110';
'F': Result := Result + '1111';
end;
end;
function StrToBinary(Str : String) : String;
begin
Result := HexToBinary(StrToHex(Str));
end;
function BinaryToStr(Bin : String) : String;
begin
Result := HexToStr(BinaryToHex(Bin));
end;
function IntToBinary(Int : Integer) : String;
begin
Result := StrToBinary(IntToStr(Int));
end;
function BinaryToInt(Bin : String) : Integer;
begin
Result := StrToIntDef(BinaryToStr(Bin), -1);;
end;
2011-02-02 17:01:12
2011-02-02 17:08:45
2011-02-02 17:29:41
From: FrementMe too :)
@Zyt3x: I'm sure there are more easier ways then that?
2011-02-02 17:52:29
function IntToBinary(value:LongInt; digits:integer):string;
begin
result := StringOfChar ('0', digits) ;
while value > 0 do begin
if (value and 1) = 1 then
result [digits] := '1';
dec (digits) ;
value := value shr 1;
Writeln(value);
end;
end;andfunction BinaryToInt(Value: String): LongInt;
var i: Integer;
begin
Result:=0;
while Copy(Value,1,1)='0' do
Value:=Copy(Value,2,Length(Value)-1) ;
for i:=Length(Value) downto 1 do
if Copy(Value,i,1)='1' then
Result:=Result+(1 shl (Length(Value)-i)) ;
end;2011-02-02 17:55:33
2011-02-03 01:19:25
2011-02-03 01:26:08
2011-02-03 01:39:04
2011-02-03 01:41:41
From: Sex
So 16 locations?
2011-02-03 01:50:59
2011-02-03 05:19:07
var
// Spell toggles (0:combat,1:teleport,2:misc,3:skill,4:defensive)
fMagic_toggles:array [0..4] of boolean;
fMagic_toggle_loc:array [0..4] of TBox;
// Current spell category toggles
fMagic_mode:integer;
type fMagic_location = record
loc:array [0..15]of TBox;
visible:array [0..15] of boolean;
default_mode:integer;
end;
procedure fMagic_changemode(mode:integer);
var i:integer;
n,o:string;
begin
o := IntToBinary(fMagic_mode,4);
fMagic_mode := mode;
n := IntToBinary(mode,4);
for i := 1 to 4 do
begin
if not(n[i] = o[i]) then
begin
{fMagic_toggles[i-1] := IntToBool(StrToInt(n[i]));
ClickBox(fMagic_toggle_loc[i-1], true);
fDebug('fMagic','Changing fMagic_toggles['+tostr(i-1)+'] to '+tostr(inttobool(n[i]))+'.');}
end;
end;
end;
function fMagic_click(slot:fMagic_location):boolean;
begin
//if not GetGameTab = tab_magic then GameTab(tab_magic);
if slot.visible[fMagic_mode] then
begin
fDebug('fMagic','Spell slot is visible, clicking.');
ClickBox(slot.loc[fMagic_mode],true);
end else
begin
fDebug('fMagic','Spell slot is not visible, changing spell toggles.');
fMagic_changemode(slot.default_mode);
ClickBox(slot.loc[fMagic_mode],true);
end;
end;
type fMagic_spell = record
loc:fMagic_location;
typ:integer;
end;
var
fMagic_Teleboxes:array [0..12] of TBox;
fMagic_falador,fMagic_telegrab:fmagic_spell;
function fTeleport(city:string):boolean;
var c:integer;
a:array [0..12] of boolean;
begin
case city of
'home': c:= 0;
'armies': c:= 1;
'varrock': c:= 2;
'lumbridge': c:= 3;
'falador': c:= 4;
'house': c:= 5;
'camelot': c:= 6;
'watchtower': c:= 7;
'trollheim': c:= 8;
'ape': c:= 9;
'otherlumbridge': c:=10;
'otherfalador': c:=11;
'othercamelot': c:=12;
end;
a[4] := true;
if not a[c] then
begin
fDebug('fMagic','This teleport is not yet supported!');
break;
end;
case c of
4: fMagic_click(fMagic_falador);
end;
result := MeInBox(fMagic_teleboxes[c]);
end;
procedure fMagic();
begin
fMagic_falador.typ := 1;
fMagic_falador.loc.default_mode := 6;
fMagic_falador.loc.loc[6] := TBox(564,245,580,261);
fMagic_falador.loc.visible[6] := true;
fMagic_telegrab.typ := 2;
fMagic_telegrab.loc.default_mode := 6;
fMagic_telegrab.loc.loc[6] := TBox(707,222,725,235);
fMagic_telegrab.loc.visible[6] := true;
end;