Autor Beitrag
Jojojoxx
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 386



BeitragVerfasst: So 19.10.08 12:14 
Hallo!

Ich nutze zur Zeit ein wenig C für einen Mikrocontroller und habe eine einfache Frage, weiß aber nicht, ob sich C und C# darin unterscheiden. Zu meiner Frage.

Ich habe zwei Variablen des Typs uint8_t, also 8-Bit Integers. Nun möchte ich beide Zahlen hintereinander auf einer uint16_t (also 16-Bit) speichern.
Aus z.b. 01100011 und 11010010 soll 0110001111010010 werden, und es soll also keine Addition der beiden Zahlen stattfinden. Mit welchem Operator ist das möglich?
Danke euch!
mfg

Jojo
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19339
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 19.10.08 12:28 
ausblenden C#-Quelltext
1:
2:
3:
  uint8_t a = 111;
  uint8_t b = 121;
  uint16_t c = a + (b << 8);
Jojojoxx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 386



BeitragVerfasst: So 19.10.08 12:37 
Alles klar!
Vielen Dank für deine Hilfe!
mfg

Jojo
Jojojoxx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 386



BeitragVerfasst: Mo 20.10.08 20:21 
Eine Frage hab ich doch noch dazu. Ein Bitshift um 8 Stellen bei einer 8-Bit Variable müsste doch keine Auswirkung haben, oder? In dem Fall bei (b << 8 )
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19339
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 21.10.08 01:41 
Es ist keine Bitrotation, zumindest wäre mir neu, wenn das die Operationen machen würden, dafür gibt es Rotationsbefehle in Assembler. Schiebst du eine 8-Bit-Variable um 8 Bit sollte sie 0 sein.

Aber ausprobiert habe ich das nicht, warum tust du das nicht einfach? ;-)