bits.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <html>
  2. <style>
  3. body {
  4. font-family: courier, fixed, sans-serif;
  5. }
  6. h1 {
  7. font-size: 1.25em;
  8. }
  9. table, td {
  10. border: 1px #cccccc solid;
  11. }
  12. table {
  13. border-collapse: collapse;
  14. }
  15. td, th {
  16. padding: 0.3em 1em;
  17. font-size: 0.85em;
  18. }
  19. tbody tr:nth-child(odd) {
  20. background-color: #f3f3f3; /* zebra stripes */
  21. }
  22. </style>
  23. <body>
  24. <h1>Bits Cheat Sheet</h1>
  25. <table>
  26. <thead>
  27. <tr>
  28. <th>&nbsp;</th>
  29. <th>2<sup>n</sup></th>
  30. <th>Bits</th>
  31. <th>Max unsigned int</th>
  32. <th>Min signed int</th>
  33. <th>Max signed int</th>
  34. </tr>
  35. </thead>
  36. <tbody>
  37. <? foreach(range(1, 32) as $b): ?>
  38. <tr>
  39. <td>2<sup><?=$b ?></sup></td>
  40. <td><?=number_format(pow(2, $b)) ?></td>
  41. <td><?=$b ?></td>
  42. <td><?=number_format(pow(2, $b) - 1) ?></td>
  43. <td><? $num = pow(2, $b) / 2 * -1 ?><?=number_format($num) ?></td>
  44. <td><? $num = pow(2, $b) / 2 - 1 ?><?=number_format($num) ?></td>
  45. </tr>
  46. <? endforeach; ?>
  47. </tbody>
  48. </table>
  49. </body>
  50. </html>