Naum
06-20-2009, 07:48 PM
Ord
I have seen 'ord' used a few times mainly in misc/smart.scar. So I thought I'd post something from delphi basics:
What is ord?
The 'Ord' function returns an integer value for any ordinal type.
It is mainly used to convert characters into their 'numeric equivalents'
N.B Instead of using Ord() you can also use the hash key '#' and the respective key code (see the SCAR manual).
How is it used?
Ord(Arg : Variant) : Int64; //Weirdly it does not show up in the SCAR menu??
Example:
var
A : Char;
C : Char;
W : WideChar;
E : Boolean;
I : Integer;
I64 : Int64;
begin
// Set the ordinal type values
A := ''''; //Place it comes in on the anscii table
C := 'C'; //Place it comes in on the anscii table
W := 'W'; //Place it comes in on the anscii table
E := True; //False = 0, True = 1.
I := 22;
I64 := 64;
// And show the value of each
WriteLn('A = '+IntToStr(Ord(A)));
WriteLn('C = '+IntToStr(Ord(C)));
WriteLn('W = '+IntToStr(Ord(W)));
WriteLn('E = '+IntToStr(Ord(E)));
WriteLn('I = '+IntToStr(Ord(I)));
WriteLn('I64 = '+IntToStr(Ord(I64)));
end.
To help you also look at the ASCII table in the SCAR manual.
If you have difficulty with understanding these types try reading here (http://www.villavu.com/forum/showthread.php?t=40661)
Chr
Definition:
The Chr function converts an IntValue integer into either an AnsiChar or WideChar as appropriate.
My definition: Does the opposite of ord, converts the integer value of a char back into it.
How is it used?
Chr(IntValue : Integer) : String;
Example:
var
tab : char;
crlf : string;
begin
// Show the use of Chr
tab := Chr(9);
crlf := Chr(13)+Chr(10);
WriteLn('Hello'+tab+'World');
WriteLn('');
WriteLn('Hello'+crlf+'World');
WriteLn('');
// Show the equivalent use of ^
tab := 'I'; // I = 9th capital of the alphabet
crlf := 'MJ'; // M = 13th, J = 10th letters
WriteLn('Hello'+tab+'World');
WriteLn('');
WriteLn('Hello'+crlf+'World');
end;
I have seen 'ord' used a few times mainly in misc/smart.scar. So I thought I'd post something from delphi basics:
What is ord?
The 'Ord' function returns an integer value for any ordinal type.
It is mainly used to convert characters into their 'numeric equivalents'
N.B Instead of using Ord() you can also use the hash key '#' and the respective key code (see the SCAR manual).
How is it used?
Ord(Arg : Variant) : Int64; //Weirdly it does not show up in the SCAR menu??
Example:
var
A : Char;
C : Char;
W : WideChar;
E : Boolean;
I : Integer;
I64 : Int64;
begin
// Set the ordinal type values
A := ''''; //Place it comes in on the anscii table
C := 'C'; //Place it comes in on the anscii table
W := 'W'; //Place it comes in on the anscii table
E := True; //False = 0, True = 1.
I := 22;
I64 := 64;
// And show the value of each
WriteLn('A = '+IntToStr(Ord(A)));
WriteLn('C = '+IntToStr(Ord(C)));
WriteLn('W = '+IntToStr(Ord(W)));
WriteLn('E = '+IntToStr(Ord(E)));
WriteLn('I = '+IntToStr(Ord(I)));
WriteLn('I64 = '+IntToStr(Ord(I64)));
end.
To help you also look at the ASCII table in the SCAR manual.
If you have difficulty with understanding these types try reading here (http://www.villavu.com/forum/showthread.php?t=40661)
Chr
Definition:
The Chr function converts an IntValue integer into either an AnsiChar or WideChar as appropriate.
My definition: Does the opposite of ord, converts the integer value of a char back into it.
How is it used?
Chr(IntValue : Integer) : String;
Example:
var
tab : char;
crlf : string;
begin
// Show the use of Chr
tab := Chr(9);
crlf := Chr(13)+Chr(10);
WriteLn('Hello'+tab+'World');
WriteLn('');
WriteLn('Hello'+crlf+'World');
WriteLn('');
// Show the equivalent use of ^
tab := 'I'; // I = 9th capital of the alphabet
crlf := 'MJ'; // M = 13th, J = 10th letters
WriteLn('Hello'+tab+'World');
WriteLn('');
WriteLn('Hello'+crlf+'World');
end;