Results 1 to 6 of 6

Thread: AS3 ByteArray wierd function pairing?

  1. #1
    HarryPorter's Avatar
    79
    posts
    & the journey into Flash

    AS3 ByteArray wierd function pairing?

    ByteArray has

    writeByte(value:int):void
    writeShort(value:int):void

    but 2 versions of int

    writeInt(value:int):void and writeUnsignedInt(value:uint):void

    Why so?

  2. #2
    TheCanadian's Avatar
    10,251
    posts
    Noo doot aboot it, eh?
    It's not two versions of int. One writes an int and the other writes a uint (unsigned int or positive integer). Both are 4 bytes but ints use one bit for the sign. uints can't store negative numbers but can store numbers twice as large as int can. You also have writeDouble and writeFloat for working with floating point numbers.
    Proud Montanadian
    We tolerate living and breathing. And niches.

    Name Brand Watches

    Maybe getTimer() or TweenMax is the answer to your problem . . .

  3. #3
    HarryPorter's Avatar
    79
    posts
    & the journey into Flash
    Quote Originally Posted by TheCanadian View Post
    It's not two versions of int. One writes an int and the other writes a uint (unsigned int or positive integer). Both are 4 bytes but ints use one bit for the sign. uints can't store negative numbers but can store numbers twice as large as int can. You also have writeDouble and writeFloat (and writeShort, which you mentioned) for working with floating point numbers.
    Hello Canadian,
    Then why don't they have writeUnsignedByte() and writeUnsignedShort() as well???
    Last edited by HarryPorter; May 9th, 2012 at 01:51 AM.

  4. #4
    TheCanadian's Avatar
    10,251
    posts
    Noo doot aboot it, eh?
    My guess would be that, since there is no native byte and short data types in AS3, a method to write them is unnecessary. You can see that writeByte and writeShort accept an int as an argument and simply ignore higher bits beyond their capacity. Additionally, you can simply read a signed byte as an unsigned byte with two's complement so you shouldn't really need methods to specifically write unsigned bytes and shorts. There are readUnsignedByte and readUnsignedShort methods.
    Proud Montanadian
    We tolerate living and breathing. And niches.

    Name Brand Watches

    Maybe getTimer() or TweenMax is the answer to your problem . . .

  5. #5
    HarryPorter's Avatar
    79
    posts
    & the journey into Flash
    Quote Originally Posted by TheCanadian View Post
    My guess would be that, since there is no native byte and short data types in AS3, a method to write them is unnecessary. You can see that writeByte and writeShort accept an int as an argument and simply ignore higher bits beyond their capacity. Additionally, you can simply read a signed byte as an unsigned byte with two's complement so you shouldn't really need methods to specifically write unsigned bytes and shorts. There are readUnsignedByte and readUnsignedShort methods.
    Hello Canadian,
    Regarding the writeUnsignedInt() and writeInt()

    var i:int = -6;
    var b:ByteArray = new ByteArray();
    b.writeUnsignedInt(i); // writes 0xFFFFFFFA
    b.writeInt(i); // writes 0xFFFFFFFA

    Since the bit pattern is same. Why 2 methods?
    And any I have 2 read methods so why not have only 1 method like writeUnsignedInt()

  6. #6
    I think the C++ semantics for casting between int and uint are the same as the AS3's, so it might just be an alias for convenience. Or an oversight.

    The implementation is the same except for the cast, which, like I said, should have the same semantics.

    PHP Code:
    // C++
    void ByteArrayObject::writeInt(int value){
        
    write32((uint32_t)value);
    }

    void ByteArrayObject::writeUnsignedInt(uint32_t value){
        
    write32(value);


Thread Information

Users Browsing this Thread

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

Tags for this Thread

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012