rfc:binnotation4ints

Differences

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

Link to this comparison view

Next revisionBoth sides next revision
rfc:binnotation4ints [2010/11/11 22:24] – created jharrisrfc:binnotation4ints [2010/11/11 22:36] – First draft jharris
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 22: Line 28:
  
 ===== Changelog ===== ===== Changelog =====
- 
  
  
rfc/binnotation4ints.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1