Autor Beitrag
Hagbard
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 142

Win XP Home / Pro
D7.1 Architekt
BeitragVerfasst: Do 03.06.04 10:42 
Hallo zusammen,

ich habe ein BitArray (TBits.Bits[i]).
Kann mir evt. jemand einen Tip geben, wie Ich jeweils 8Bit wieder in einen Char verwandeln kann?


Gruß,
Christian


Moderiert von user profile iconTino: Topic aus VCL (Visual Component Library) verschoben am Do 03.06.2004 um 11:54

_________________
I haven't failed, I just found 10,000 ways that won't work!
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: Do 03.06.04 17:28 
wenn du auf die 8 Bits mit TBits.Bit[0]..TBits.Bit[7] zugreifst dürfte das so gehen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var i: integer;
    c: char;
{...}
c := 0;
for i := 0 to 7 do
begin
  c := c + TBits.Bit[i];
  c := c shl 1;
end;

allerdings müssen die 8 bit so angeordnet sein:
ausblenden Quelltext
1:
2:
bit0 bit1 bit2 ... bit6 bit7
=128  =64  =32      =2   =1


raziel

_________________
JSXGraph
fritierte
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 58



BeitragVerfasst: Do 03.06.04 17:47 
so gehts auch mit binär-bits

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
for i := 0 to 7 do
begin
  c := c + power(TBits.Bit[i],i);
  c := c shl 1;
end;
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: Fr 04.06.04 09:58 
fritierte hat folgendes geschrieben:
so gehts auch mit binär-bits

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
for i := 0 to 7 do
begin
  c := c + power(TBits.Bit[i],i);
  c := c shl 1;
end;


denke nicht dass das geht.
TBits.Bit[i] ist entweder 0 oder 1.
egal mit was du 0 bzw 1 "hochnimmst", es kommt immer 0 bzw 1 raus.
> d.h. deine methode ist exakt die gleiche wie meine, außer dass sie evtl n bissl länger braucht... ;-)

btw: was bitte sind binär-bits?

raziel

_________________
JSXGraph
fritierte
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 58



BeitragVerfasst: Fr 04.06.04 13:01 
sorry war ein denkfehler von mir, soll eigentlich so lauten
ausblenden Delphi-Quelltext
1:
2:
3:
4:
for i := 0 to 7 do
begin
  c := c + power(2,i)*TBits.Bit[i];
end;
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: Fr 04.06.04 13:07 
dacht ich mir fast...
aber trotzdem: was bitte sind binär-bits? :D

_________________
JSXGraph