Bytes 'n bytes

This topic contains 22 replies, has 4 voices, and was last updated by  SekaiChi 1 month ago.

Viewing 15 posts - 1 through 15 (of 23 total)
  • Author
    Posts
  • #14397

    SekaiChi
    Participant

    Why do you get these numbers ?

    #14401

    Simon Armstrong
    Participant

    As opposed to what? The behavior is correct and reflects how casting to signed and unsigned data types works with all computer languages where a byte is defined as an 8 bit binary value.

    #14402

    SekaiChi
    Participant

    As apposed to what we wrote inside the source code.

    How do you mean?

    Okay, how do this work?

    #14403

    SekaiChi
    Participant

    Unsigned bytes

    Why is 255 & -1  =  0 instead of 255? -1 is all one bits except one, and we mask all bits but the 8 lowest bits. So all bits should be 1’s = 255.

     

     

    The signed bytes below are harder to explain but if  the above is explained that’s probably enough to understand these aswell.
    The questions where (not stupid at all) these questions:

    Why is 255 & 255 =  -1 and not 255?
    Why is 128 & 255 = -128 and not 0?
    Why is -1 & 255  =  -1 and not 255?

    I know it’s about the interpretation of the actual values in edit time and runtime swell, but how are you supposed to reason about this?

    #14404

    SekaiChi
    Participant

    Any other demo coders in the building? Need help.

    #14405

    SekaiChi
    Participant

    Ahh the value is seen as a 2nd complement AFTERWARDS, I’m stupid. Okay gotcha. Of course.

    I just read BYTE and thought 0-255.  0-255 0 -255 0 -255 It’s signed.

     

    But the unsigned one I haven’t got around yet to understand.

    #14406

    Jesse
    Participant

    a signed bite only goes upto 128 and down to -128 which is the first 7 bits and are used as the number and the last bit “on” for negative and “off” for positive. if you pass a number greater than 128 it sets the last bit to on and therefore it returns a negative number and will be a completely different number that you passed as interpreted by the compiler.

    in a signed byte a negative 1 in a byte binary equals 11111111 and in an unsigned byte the 11111111 is equal to 255. The last bit of a signed byte will always be used to represent whether the number is positive or negative. and that goes back all the way to the original assembly language.

    #14407

    SekaiChi
    Participant

    no it goes up to 127

    #14408

    Jesse
    Participant

    Yea my fault something like that. I believe it goes down to -128.

    #14409

    SekaiChi
    Participant

    The unsigned is the only one left to explain and I think I understand it now too

    -1 is interpreted all one bits so so it will give 255

     

    So the thing that was fuzzy was that the functions where defined to get input and output of certain type.

    And that type needs to be converted at the call of the function.

     

    That conversion was the source of confusion. It needs time to get used to.

    #14410

    SekaiChi
    Participant

    Is there a SAR in this language? Is there a way  to do that? Maybe integer division? << >> >>>

    #14411

    Jesse
    Participant

    I don’t know. Mark might have to answer that. I don’t think he has it integrated in the language and I don’t know if he would be willing to add it.

    on another note, here is a little bit of code to kind of explain what I said before:

    [/crayon]

    [edited]
    had the representation of the math backwards.

    #14412

    Jesse
    Participant

    try this video if you have time:

    #14413

    SekaiChi
    Participant

    Thanks, ya it’s good to be clear about things.

    Okay if it’s not implemented we can use something that does the same thing.

    Something like x = Floor(x/2) ‘ Sar x,1 (but sometimes the correct Sar for a negative x would be -Ceil(-x / 2) when you use 2nd complement. It’s just an oddity to watch for out for.

    #14414

    SekaiChi
    Participant

    Building an arcade emulator around a few processors and thinking of making it open-source if it turns out alright.

    It’s all Monkey2 code and it tries to avoid externals, maybe there will be some externals we’ll see but it’s a fun project and very good practice.

    It’s understandable if Mark doesn’t want to put low-level in there no worries but I would’ve guessed that there were an integer division that fulfilled the purpose of what Sar does. A hidden low-level element, a hackers kinder surprise.

Viewing 15 posts - 1 through 15 (of 23 total)

You must be logged in to reply to this topic.