ビットシフトが気になって…

by mezumona forked from trace を swf 上に。 (diff: 14)
仕方が無くなり、眠れなくなったので。
ところが、<< -1 の罠に嵌り余計眠れなくなったとさ。
♥0 | Line 34 | Modified 2011-04-01 03:15:31 | MIT License
play

ActionScript3 source code

/**
 * Copyright mezumona ( http://wonderfl.net/user/mezumona )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/z5b7
 */

package {
    import flash.text.TextFormat;
    import flash.display.Sprite;
    import flash.display.DisplayObjectContainer;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;

    /**
     * 仕方が無くなり、眠れなくなったので。
     */
    public class FlashTest extends Sprite
    {
        public function FlashTest()
        {
            initializeTrace(this);
            trace("0x11 <<   1 : ", 0x11 << 1);
            trace("0x11 >>  -1 : ", 0x11 >> -1, "\t\t\t// 0 になっちゃうのかー");
            trace("0x11 >>> -1 : ", 0x11 >>> -1, "\t\t\t// ならこれも 0 かな。");
            trace("\n//なら…");
            trace("0x11 >>   1 : ", 0x11 >> 1);
            trace("0x11 <<  -1 : ", 0x11 << -1, "\t// !?");
            trace("0x11 <<  30 : ", 0x11 << 30, "\t// まさか…");
            trace("0x11 <<  32 : ", 0x11 << 32, "\t\t\t// 内部で丸められていたのか…");
            trace("0x11 >> -32 : ", 0x11 >> -32, "\t\t\t// この感じ… '& 0x1F' か…");
        }

        private var tf_:TextField = new TextField();
        public function trace(...rest):void
        {
            tf_.appendText(rest.join(" ") + "\n");
        }

        public function initializeTrace(target:DisplayObjectContainer):void
        {
            tf_.autoSize = TextFieldAutoSize.LEFT;
            tf_.defaultTextFormat = new TextFormat("_等幅", 12);
            target.addChild(tf_);
        }

    }
}