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.

Binärdaten in BIT-Array umwandeln

Empfohlene Antworten

Veröffentlicht

Hallo,

ich möchte in einem PHP-Skript eine Binärdatei interpretieren, in der nicht immer ein ganzes Byte einem Wert entspricht, sondern die einzelnen Bits eines Bytes.

Kennt jemand eine Funktion oder einen einfachen Weg, um ein ASCII-Zeichen oder einen hexadezimalen Wert in einen Array aus acht Wahrheitswerten zu zerlegen?

Ich komme zwar mit base_convert ein Stück weit, jedoch entfallen dabei führende Nullen, sodass man das Ergbnis nicht so ohne Weiteres in einen Array umwandeln kann.

  • Autor

So ähnlich... nur dass eben kein String heraus kommt, sondern ein aufgefüllter Array

statt decbin(12) = "1100" -> array(0,0,0,0,1,1,0,0)

aktuell weiche ich über folgende Funktion aus:


function hexBitarray($value)

        {

        $io = base_convert((string)$value,16,2);

        for($i=0;$i<8;$i++)

                $b[$i]=0;

        for($i=8-strlen($io);$i<8;$i++)

                $b[$i]=substr($io,$i-(8-strlen($io)),1);

        return $b;

        }

Würde das aber gerne eleganter lösen und falls möglich auf eine eigene Funktion verzichten.

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.