Skip to Main Content
PHP 5 Kochbuch, Third Edition
book

PHP 5 Kochbuch, Third Edition

by David Sklar, Adam Trachtenberg, Carsten Lucke, Matthias Brusdeylins, Ulrich Speidel, Stephan Schmidt
September 2009
Intermediate to advanced content levelIntermediate to advanced
912 pages
48h 11m
German
O'Reilly Verlag
Content preview from PHP 5 Kochbuch, Third Edition

2.15 Mit anderen Zahlen als Dezimalzahlen rechnen

Problem

Sie möchten mathematische Operationen mit Zahlen ausführen, die nicht als Dezimalzahlen, sondern als Oktal- oder Hexadezimalzahlen formatiert sind. Beispielsweise möchten Sie websichere Farben in Hexadezimal-Darstellung ausrechnen.

Lösung

Stellen Sie der Zahl ein führendes Symbol voran, an der PHP erkennt, dass es sich nicht um Basis 10 handelt. Die folgenden Werte sind alle gleich:

0144  // Basis 8
 100  // Basis 10
0x64  // Basis 16

Hier sehen Sie, wie man von 1 bis 15 (dezimal) zählen kann, dabei aber eine hexadezimale Darstellung verwendet:

for ($i = 0x1; $i < 0x10; $i++) { print "$i\n"; }

Diskussion

Auch wenn Sie hexadezimal formatierte Zahlen in einer for-Schleife benutzen, werden normalerweise ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP programmieren unter Windows

PHP programmieren unter Windows

Arno Hollosi
CSS Kochbuch, 3rd Edition

CSS Kochbuch, 3rd Edition

Joergen Lang, Christopher Schmitt

Publisher Resources

ISBN: 9783868993271Purchase book