Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Int in Byte

Empfohlene Antworten

Veröffentlicht

Hallo Community,

ich habe mal wieder eine Fragen :(:D

Ich habe eine 12 Bit große Zahl ( Digital-to-Analog Converter).

Diese 12 Bit große Zahl muss ich nun in 2 Teile zerlegen!

Die höherwertigsten 4 Bit ( vom MSB rückwärts gezählt) müssen in eine byte Variable.

Die hinterstens 8 Bit müssen in eine weitere Variable.

Wie bekomme ich das gelöst?

Zur weiteren Erklärung, Ausgangssitaution:

12 Bit Zahl (z.B. 1011 0110 1110)

Die ersten 4 Bit müssen in eine Variable also variable1 = 1011

Die letzten 8 Bit müssen in eine Variable also variable2 = 0110 1110

Ich hoffe ihr könnt mir helfen

Ja habs hin bekommen... Also sowas hier hab ich gesucht


 UINT16 u8_MASK = 000011111111;


    UINT8 u8_4BitMSB = u16_value>>8;

    UINT8 u8_8BitLSB = u16_value&u8_MASK;

    UINT8 u8_cmdValReg = u8_cmdReg | u8_4BitMSB;

UINT16 u8_MASK = 000011111111;

Das funktioniert nicht. C und C++ kennen keine Literale für Dualzahlen. u8_MASK hat nicht den erwarteten Wert 255, sondern 37449, weil Zahl-Literale, die mit einer 0 beginnen, als oktal interpretiert werden.

Setz u8_MASK auf 255 oder 0xff, dann passt das.

Wieso funktioniert das so nicht? Also ich verstehe die Begründung nicht. Ich bin hier ja bei C. Wenn ich hier jetzt z.B. 0b000011111111 schreibe funktioniert das ...

Ok das ist gut möglich. Also die von mir gepostete Lösung funktioniert.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.