Results 1 to 6 of 6

Thread: Value of Type: Byte

  1. #1
    Join Date
    Jan 2012
    Location
    Netherlands
    Posts
    76
    Mentioned
    0 Post(s)
    Quoted
    3 Post(s)

    Default Value of Type: Byte

    Today i was making a list of the Types that can be used and i got this weird thing.

    A byte contains 8 bits.
    That means the value should be between 0-255
    Min: (2^0)-1 = 0
    Max: (2^8)-1 = 255
    But this is definitely exceeded since i can do this:

    Simba Code:
    program Variables;
    {$DEFINE SMART}

    var  
    example : Byte ;  

    begin
    example := 1944670000000000000000000 ;

    end.

    Compiled successfully in 15 ms.
    Successfully executed.
    Last edited by kazhual; 10-31-2012 at 01:21 PM. Reason: forgot some text

  2. #2
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Yes you can do that but it will result in integer overflow, meaning that it will start counting from start again. Eg. 255=255, 256=0, 257=1..and the cycle repeats.

    If you do writeln(example) it will not return any value higher than 255.

    This is a common feature/problem in almost all processors. (and it has famously turned suomi to rank 1900+ when his total xp exceeded the maximum integer of unsigned 32 bit)

  3. #3
    Join Date
    Nov 2006
    Posts
    2,369
    Mentioned
    4 Post(s)
    Quoted
    78 Post(s)

    Default

    Actually it just seems to return 0 when set to hundreds of billions.
    Quote Originally Posted by DeSnob View Post
    ETA's don't exist in SRL like they did in other communities. Want a faster update? Help out with updating, otherwise just gotta wait it out.

  4. #4
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Quote Originally Posted by weequ View Post
    Actually it just seems to return 0 when set to hundreds of billions.
    Nope, you are just lucky enough (1/256 chance) to hit the 0th number, try increasing it by a bit.

    EDIT: oh you are right, it turns 0 when the number of digits exceed 19. Maybe that's just because Simba can't handle it.

  5. #5
    Join Date
    Oct 2011
    Posts
    422
    Mentioned
    15 Post(s)
    Quoted
    116 Post(s)

  6. #6
    Join Date
    Jan 2012
    Location
    Netherlands
    Posts
    76
    Mentioned
    0 Post(s)
    Quoted
    3 Post(s)

    Default

    I just did not expect an overflow but the error that it is out of range, like HEX better for such things

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •