Форум: "Основная";
Текущий архив: 2003.09.18;
Скачать: [xml.tar.bz2];
Вниза как бы это по красивее сделать ... Найти похожие ветки
← →
titnn (2003-09-07 09:00) [0]
type
Arr256 = array[0..255] of byte;
function StrToArrByte(str: string): Arr256;
var i: integer;
begin
for i:=0 to (length(str) div 2)-1 do result[i]:=StrToInt("$"+str[i*2+1]+str[i*2+2]);
end;
var bArray: arr256;
bArray:=StrToArrByte("3FC7A00001");
← →
titnn (2003-09-07 09:01) [1]в смысле саму ф-цию ...
← →
MBo (2003-09-07 09:30) [2]да в общем нормально. Можно copy воспользоваться, но это особо красоты не прибавит.
Вот только такой момент - читать надо с конца или при нечетном количестве символов это учитывать.
← →
Романов Р.В. (2003-09-07 12:05) [3]В общем случае нужна проверка на валидность символов
← →
Danilcha (2003-09-07 13:51) [4]
const
hcUnknown = $FF;
var
HexCharValues: array [Char] of Byte;
type
TByteArray = array of Byte;
function StrToByteArray(S: String): TByteArray;
var
I, L, CountOfBytes: Integer;
Ch1, Ch2: Char;
B1, B2: Byte;
begin
L := Length(S);
CountOfBytes := L div 2;
SetLength(Result, CountOfBytes);
for I := 0 to CountOfBytes - 1 do
begin
Ch1 := S[I * 2 + 1];
Ch2 := S[I * 2 + 2];
B1 := HexCharValues[Ch1];
B2 := HexCharValues[Ch2];
if (B1 = hcUnknown) or (B2 = hcUnknown) then
raise Exception.Create("Invalid char at " + IntToStr(I) + " byte.");
Result[I] := B1 * 16 + B2
end
end;
procedure InitHexCharValues;
var
C: Char;
begin
for C := Low(Char) to High(Char) do
HexCharValues[C] := hcUnknown;
for C := "0" to "9" do
HexCharValues[C] := Ord(C) - Ord("0");
HexCharValues["A"] := $A; HexCharValues["a"] := $A;
HexCharValues["B"] := $B; HexCharValues["b"] := $B;
HexCharValues["C"] := $C; HexCharValues["c"] := $C;
HexCharValues["D"] := $D; HexCharValues["d"] := $D;
HexCharValues["E"] := $E; HexCharValues["e"] := $E;
HexCharValues["F"] := $F; HexCharValues["f"] := $F;
end;
begin
InitHexCharValues
end.
← →
Proton (2003-09-08 00:37) [5]
const
// разрыв строки
lb = #13#10;
// hex const array
hcarr : array[byte] of string[2] = (
"00","01","02","03","04","05","06","07","08","09","0A","0B",
"0C","0D","0E","0F","10","11","12","13","14","15","16","17",
"18","19","1A","1B","1C","1D","1E","1F","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","7F","80","81","82","83",
"84","85","86","87","88","89","8A","8B","8C","8D","8E","8F",
"90","91","92","93","94","95","96","97","98","99","9A","9B",
"9C","9D","9E","9F","A0","A1","A2","A3","A4","A5","A6","A7",
"A8","A9","AA","AB","AC","AD","AE","AF","B0","B1","B2","B3",
"B4","B5","B6","B7","B8","B9","BA","BB","BC","BD","BE","BF",
"C0","C1","C2","C3","C4","C5","C6","C7","C8","C9","CA","CB",
"CC","CD","CE","CF","D0","D1","D2","D3","D4","D5","D6","D7",
"D8","D9","DA","DB","DC","DD","DE","DF","E0","E1","E2","E3",
"E4","E5","E6","E7","E8","E9","EA","EB","EC","ED","EE","EF",
"F0","F1","F2","F3","F4","F5","F6","F7","F8","F9","FA","FB",
"FC","FD","FE","FF");
Function BinData2BinStr(const buf:pointer; const count:integer):string;
var i,j:integer;
begin
j := 0;
for i:= 0 to count-1 do
begin
if j >= 20 then
begin
Result := Result + lb;
j := 0;
end;
Result := Result + hcarr[byte(pointer(integer(buf)+i)^)];
inc(j);
end;
end;
Procedure BinStr2BinData(const buf:pointer; const count:integer;const str:string);
var i,j:integer;
s:string;
k:byte;
begin
j := 0;
s := "";
for i := 1 to length(str) do
begin
if str[i] in ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"] then
s := s + str[i];
if length(s) = 2 then
begin
for k := 0 to 255 do
begin
if hcarr[k] = s then
begin
if j<count then
byte(pointer(integer(buf)+j)^) := k;
break;
end;
end;
s := "";
inc(j);
end;
end;
end;
BinStr2BinData(@XmlScannerCurPage.bookmarks,
sizeof(XmlScannerCurPage.bookmarks),content);
result := result + StrafeRight(BinData2BinStr(@(bookmarks),sizeof(bookmarks)),level+2);
Страницы: 1 вся ветка
Форум: "Основная";
Текущий архив: 2003.09.18;
Скачать: [xml.tar.bz2];
Память: 0.47 MB
Время: 0.009 c