I'm not sure as to why I'm not getting a response on this. Wrong post? I have code below, however crude, that seems to obtain at least the 8 bit binary values of an ASCII char. What am I doing wrong on the 6 bit? I get all zeros. First, this is my logic for decoding Base64:
Get character(s)
Get decimal value of each character
Convert decimal value to 6 bit binary for each character
Concatenate string of 6 bit binary values
Divide string by 8 characters (8 bit binary value)
Obtain decimal value of each 8 bit string
Get ASCII value of decimal
R1 := 1;
M:=1;
while (R1 <= 255) do begin
// Get 8 bit binary value
Str := chr(R1);
M := abs(M);
S := '';
for i:=1 to SizeOf(M)*8 do begin
if M<0 then begin
S:=S+'1'
end
else begin
S:=S+'0';
end;
M:=M shl 1;
end;
Delete(S,1,Pos('1',S)-1);
// Get 6 bit binary ????
M := R1;
M := abs(M);
t := '';
for i:=1 to SizeOf(M)*6 do begin
if M<0 then begin
t:=t+'1'
end
else begin
t:=t+'0';
end;
M:=M shl 1;
end;
Delete(t,1,Pos('1',t)-1);
if (length(s) = 1) then begin
s := '0000000'+s;
end
else if (length(s) = 2) then begin
s := '000000'+s;
end
else if (length(s) = 3) then begin
s := '00000'+s;
end
else if (length(s) = 4) then begin
s := '0000'+s;
end
else if (length(s) = 5) then begin
s := '000'+s;
end
else if (length(s) = 6) then begin
s := '00'+s;
end
else if (length(s) = 7) then begin
s := '0'+s;
end;
if (length(t) = 1) then begin
t := '00000'+t;
end
else if (length(t) = 2) then begin
t := '0000'+t;
end
else if (length(t) = 3) then begin
t := '000'+t;
end
else if (length(t) = 4) then begin
t := '00'+t;
end
else if (length(t) = 5) then begin
t := '0'+t;
end;
cTbl.insert;
cTbl.fieldByName('Decimal').asInteger := R1;
cTbl.fieldByName('Letter').asString := chr(R1);
cTbl.fieldByName('Bit8').asString := s;
cTbl.fieldByName('Bit6').asString := t;
cTbl.post;
R1 := R1 + 1;
M := R1;
end;
cTbl.active := True;
Getting answers before I'm asked
is why I go to Tek-Tips.