AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

"Einsenfüller" in Assembler?

Ein Thema von MaOfDe · begonnen am 16. Dez 2007 · letzter Beitrag vom 16. Dez 2007
 
Hawkeye219

Registriert seit: 18. Feb 2006
Ort: Stolberg
2.227 Beiträge
 
Delphi 2010 Professional
 
#7

Re: "Einsenfüller" in Assembler?

  Alt 16. Dez 2007, 22:26
Hi,

man kann die folgende Routine sicher noch optimieren, für den Anfang sollte sie aber genügen:

Delphi-Quellcode:
function BitCount (Data: Byte): Integer;
const
  Bits : array [0..15] of Byte
       = (0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4);
begin
  Result := Bits[Data shr 4] + Bits[Data and 15];
end;

procedure FillBits (var X; Size, NumBits: Integer);
var
  BitPos : Integer;
  Index : Integer;
  Space : Integer;
  Buffer : array [0..MaxInt - 1] of Byte absolute X;
begin
  for Index := 0 to Size - 1 do
    Dec (NumBits, BitCount(Buffer[Index]));

  Index := 0;
  while ((Index < Size) and (NumBits > 0)) do
    begin
      Space := 8 - BitCount(Buffer[Index]);
      if (NumBits >= Space) then
        Buffer[Index] := $FF
      else
        for BitPos := 0 to 7 do
          if (not Odd(Buffer[Index] shr BitPos)) then
            begin
              Inc (Buffer[Index], 1 shl BitPos);
              Dec (NumBits);
              if (NumBits = 0) then
                Exit;
            end;
      Dec (NumBits, Space);
      Inc (Index);
    end;
end;
Gruß Hawkeye
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:20 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz