Conversion décimal en 8bit

Résolu
bobstien Messages postés 38 Date d'inscription lundi 4 avril 2005 Statut Membre Dernière intervention 1 mars 2007 - 26 oct. 2006 à 07:56
bobstien Messages postés 38 Date d'inscription lundi 4 avril 2005 Statut Membre Derniè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

2 réponses

f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 35
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;





3
bobstien Messages postés 38 Date d'inscription lundi 4 avril 2005 Statut Membre Dernière intervention 1 mars 2007 1
26 oct. 2006 à 20:42
Merci beaucoup foxi pour ton aide, c est ce que je recherchais. Bonne soirée et encore merci
3
Rejoignez-nous