1 / 2

Binäres Verunden

Binäres Verunden. „Bitweises Prüfen“ & Operator macht eine bitweise Verundung zweier Zahlen Gegensatz: && logisches Und Beispiel: Zahl = 1234 d 1234 d = 0000 0100 1101 0010 b Testnumber = 1 d = 000 0000 0000 0001 b if (0000 0100 1101 0010 & Testnumber == 0) -> Bit ist 0

cole-lynch
Télécharger la présentation

Binäres Verunden

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Binäres Verunden • „Bitweises Prüfen“ • & Operator macht eine bitweiseVerundung zweier Zahlen • Gegensatz: && logisches Und • Beispiel: Zahl = 1234d • 1234d= 0000 0100 1101 0010b • Testnumber = 1d = 000 0000 0000 0001b if (0000 0100 1101 0010 & Testnumber == 0) -> Bit ist 0 0000 0000 0000 0001 0000 0000 0000 0010 0000 0000 0000 0100 … 1000 0000 0000 0000 else -> Bit ist 1 • Testnumber = Testnumber * 2 • Bei 16 Bit Zahl (unsignedshort) 16x wiederholen

  2. Module Division durch 2 • „Prüfen, ob Zahl gerade oder ungerade ist“ • 0 % 2 -> kein Rest -> Bit ist 0 • 1 % 2 -> Rest -> Bit ist 1 • Beispiel: Zahl = 1234d • 1234d = 0000 0100 1101 0010b • Zahl % 2: kein Rest -> Bit = 0 • Zahl % 2: Rest -> Bit = 1 • Zahl = Zahl / 2 -> Shift nach rechts • 0000 0100 1101 0010 -> 0000 0010 0110 1001 • Bei 16 Bit Zahl (unsignedshort) 16x wiederholen

More Related