rfc:binnotation4ints

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
rfc:binnotation4ints [2010/11/11 22:24] – created jharrisrfc:binnotation4ints [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 3: Line 3:
   * Date: 2010-11-11   * Date: 2010-11-11
   * Author: Jonah H. Harris <jonah.harris@gmail.com> / <jonah.harris@myyearbook.com>   * Author: Jonah H. Harris <jonah.harris@gmail.com> / <jonah.harris@myyearbook.com>
-  * Status: In the works+  * Status: Implemented in 5.4
  
 ===== Introduction ===== ===== Introduction =====
Line 11: Line 11:
 ===== History ===== ===== History =====
  
-As most developers know, PHP already supports octal and hexadecimal as alternatives to standard decimal notation.  As such, a developer can currently define an integer value of 2010 using 2010 (base 10), 0x7da (base 16), and 03732 (base 8).  An example of using hexadecimal notation is for bitmasks, where flag values are commonly defined using hexadecimal notation (0x01, 0x02, 0x04, 0x08, 0x10, etc.)  While this works, it isn't visually representative of the bitmask which, in addition to just being cool, is one of the reasons several of the newer languages have incorporated binary notation support.  Accordingly, a developer can specify the value 2010 as 0b11111011010 or flags as 0b00001, 0b00010, 0b00100, 0b01000, 0b10000.+As most developers know, PHP already supports octal and hexadecimal as alternatives to standard decimal notation.  As such, a developer can currently define an integer value of 2010 using 2010 (base 10), 0x7da (base 16), and 03732 (base 8). 
 + 
 +An example of using hexadecimal notation is for bitmasks, where flag values are commonly defined using hexadecimal notation (0x01, 0x02, 0x04, 0x08, 0x10, etc.)  While this works, it isn't visually representative of the bitmask which, in addition to being just plain cool, is one of the reasons several of the newer languages have incorporated binary notation support--support that allows developers to specify the value 2010 as 0b11111011010 or flags as 0b00001, 0b00010, 0b00100, 0b01000, 0b10000.
  
 ===== Proposal ===== ===== Proposal =====
  
 Given that binary notation is syntactic sugar, the proposed implementation appears to be relatively minor.  The areas requiring changes are the scanner and custom string-to-double functions. Given that binary notation is syntactic sugar, the proposed implementation appears to be relatively minor.  The areas requiring changes are the scanner and custom string-to-double functions.
 +
 +  * Scanner Changes--First, I propose adding a binary number representation ("0b"[01]+) to the scanner.  Second, add the supporting code for handling binary conversions to long/double just as is done for hexadecimal.  Lastly, add support for using the binary notation in variable offsets just as is done for the other representations.
 +
 +  * Custom string-to-double Functions--Add another strtod function, zend_bin_strtod, which converts a number from base-2 representation to an integer.  The supported syntax being valid base-2 digits [01] optionally prefixed by 0[bB].
  
 ===== Patch ===== ===== Patch =====
Line 21: Line 27:
 Preliminary source and documentation patches can be found with the ticket [[http://bugs.php.net/bug.php?id=50648]] Preliminary source and documentation patches can be found with the ticket [[http://bugs.php.net/bug.php?id=50648]]
  
-===== Changelog ===== +===== References =====
  
 +  * [[http://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html|GCC Support for Binary Literals]]
 +  * [[http://www.python.org/dev/peps/pep-3127/|Python Support for Binary Literals]]
 +  * [[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_stdtypes.html#S1|Ruby Support for Binary Literals]]
  
 +===== Changelog =====
 +implemented with http://svn.php.net/viewvc?view=revision&revision=313756
rfc/binnotation4ints.1289514278.txt.gz · Last modified: 2017/09/22 13:28 (external edit)