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.

Empfohlene Antworten

Veröffentlicht

Hallo!

Ich schreibe gerade an einem Programm welches mit IP-Adressen zu tun hat...dafür benötige ich einen Algorithmus welcher Dezimal-Zahlen in Binär umwandelt und auch Binär in Dezimal. Optimal wär wenn direkt ganze IP-Adressen umgewandelt werden können.

Kennt jemand solch einen Algorithmus? Oder gibt es sogar eine spezielle Funktion? Habe bereits gegoogelt, doch die Ergebnisse haben meist nicht funktioniert.

Danke im Voraus!

Ich versuchs mal:

FunktionsName (int MeinDezimalZahl)

{

Rest = MeinDezimalZahl % 2 // Modulo

IntegerZahl = MeinDezimalZahl / 2 // eventuell abrunden

FunktionsName (IntegerZahl) // Rekursiver Aufruf

Binärzahl= Binärzahl + Rest

}

Ist jetzt aber nur Dezimalzahl in Binärzahl.

Was soll das? Ein Computer speichert Zahlen ohnehin nur binär. Möchstest Du das Bit-Muster eines Langwortes (4 Bytes, entspricht u.a. auch einer IP-Adresse) ausgeben?

ja ich möchte das Bitmuster in einer variablen speichern...

Wenn Du z.B. einer Integer-Variablen eine Zahl zuweist, wird an ihrer Speicheradresse das Bitmuster gespeichert. Möchtest Du das Bitmuster einer Binärzahl eventuell als String ("1011...usw...") ausgeben? Oder meinst Du den Umgekehrten Weg (String mit Zahlen als Abbildung eines Bitmusters -> Zahl), wie nic_power vermutet hat?

Ich hab da mal was vorbereitet *g*

Gut dass ich meine alten Sourcen aufhebe :)


int main(int argc, char *argv[])

{

  int i;

  int iArray[32];


  std::cout << "\nBitte eine 32-bit Ganzzahl eingeben: ";

  std::cin >> iEingabe;


  for(i = 31; i >= 0; i--)

    {

      iArray[i] = iEingabe % 2;

      iEingabe = iEingabe / 2;

    }


  for(i = 0; i <= 31; i++)

    {

      std::cout << iArray[i];

    }

  std::cout << endl;


  return 0;

}


Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

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.