bobstien
Messages postés38Date d'inscriptionlundi 4 avril 2005StatutMembreDernière intervention 1 mars 2007
-
26 oct. 2006 à 07:56
bobstien
Messages postés38Date d'inscriptionlundi 4 avril 2005StatutMembreDernière intervention 1 mars 2007
-
26 oct. 2006 à 20:42
Bonjour,
J'ai un peti problème, je cherche à convertir un nombre décimal en binaire mais sous forme de 8 bits, j ai cherché un peu partout sans trouver de réponse. Merci d'avance por votre aide
f0xi
Messages postés4205Date d'inscriptionsamedi 16 octobre 2004StatutModérateurDernière intervention12 mars 202235 26 oct. 2006 à 19:18
type
TBitsLength = (bl4bits, bl8bits, bl16bits, bl24bits, bl32bits, bl64bits);
const
_BitsLength : array[TBitsLength] of byte = (4,8,16,24,32,64);
_BitsWordCount : array[TBitsLength] of byte = (0,1,3,5,7,15);
_BitsStrings : array[$0..$F] of array[0..3] of char = ('0000','0001','0010','0011',
'0100','0101','0110','0111',
'1000','1001','1010','1011',
'1100','1101','1110','1111');
function IntToBinStr(const I : int64; const BitLength : TBitsLength = bl32bits) : string;
var n,k : integer;
i4 : $0..$f;
PResult : PChar;
begin
SetLength(Result,_BitsLength[BitLength]);
PResult := PChar(Result);
for n := _BitsWordCount[BitLength] downto 0 do begin
i4 := (I shr (n shl 2)) and $F;
for k := 0 to 3 do
PResult[k] := _BitsStrings[i4,k];
if n > 0 then inc(PResult,4);
end;
end;