• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1329
  • Last Modified:

How to get char binary code

Hello How can I get chars binary code?
0
ILPowerSoft
Asked:
ILPowerSoft
  • 2
1 Solution
 
brunoheCommented:
try Ord(char)
0
 
ProbieCommented:
function GetCharCode(ch : char) : byte;
begin
 result := ord(ch);
end;
0
 
ILPowerSoftAuthor Commented:
I need to get the binary code as 0011 1010111
0
 
ProbieCommented:
Here is an example on how to get the binary code for an char


function raise2(v : longint; exp : byte) : longint;
var loop,t : longint;
begin
 t := v;
 if exp <> 0 then begin
  for loop := 1 to exp-1 do begin
   v := t * v;
  end;
 end else v := 1;
raise2 := v;
end;

function bytebin(v : byte) : string;
var l1,l2 : byte;
    c : word;
    st : string[8];
begin
 st := '00000000';
 l2 := 7;
 for l1 := 1 to 8 do begin
  c := raise2(2,l2);
  dec(l2);
  if (v >= c) then begin
   dec(v,c); st[l1] := '1';
  end;
 end;
 bytebin := st;
end;

function GetCharCode(ch : char) : string;
begin
 result := bytebin(ord(ch));
end;
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now