Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • byte storage format

    I have a somewhat niche question. A variable stored as a byte uses 1 byte to store a number. 1 byte is 8 bits, which can take \(2^8=256\) combinations. 26 (.a to .z) + 1 (.) are reserved for missing values, leaving 229 combinations. A byte variable can store values from -127 to 100, requiring 228 combinations. 'That leaves 1 combination unaccounted for. Did I make an error or is that 1 remaining combination used for something else?
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

  • #2
    There are two conventions for representing signed binary numbers: ones' complement and two's complement.

    https://en.wikipedia.org/wiki/Signed...epresentations
    https://en.wikipedia.org/wiki/Ones%27_complement
    https://en.wikipedia.org/wiki/Two%27s_complement

    With ones' complement there are two representations of zero: +0 which is 00000000 and -0 which is 10000000.

    With two's complement you get a single representation of zero, and negative numbers go down to -128.

    I think the difference is rooted in that distinction, although I cannot connect the dots from this theoretical discussion through computer hardware to Stata's software. Perhaps at the time Stata was written the decision was made to choose a range compatible with ones' complement representation in case Stata was ever ported to hardware based on that convention, although the vast majority of contemporary hardware is two's complement.

    Comment


    • #3
      I was going to suggest that it likely has to do with using a signed byte instead of an unsigned byte. My best guess is that there might be something that hints at this in either the header or c file for plugins.

      Comment

      Working...
      X