Bits and Bytes with AIR Part 1.

Here is part one of the series Bits and Bytes with AIR. It includes the Introduction and basic explanations of terms you`ll find in the world of bits and bytes.
Download as PDF.


When I started with programming back in 1999 (yes flash was my first “programming” experience) I basically saw two paths splitting in front of me. The one was the geeky programmers way were everything was told in 0`s and 1`s and the other was the cool graphic oriented arty multimedia web designers way were programming was just a necessary minor matter and were was a subtle chance to at least have some woman in your lecture courses.

I went well with this attitude throughout the years. I started with flash 5 and there was no real need to get into bits and bytes. From flash 5 to 6, 7 and 8 the pressure was still low. But then in 2006 Adobe released the flash player 9 and with it came new mysterious power in form of the ByteArray class. My first encounter with it was when I studied the Sound Object API and it`s soundSpectrum method. It took quite some brain tweaking until I got it to work but saying that I really understood it would be a lie. While I got worried by this I still did not felt the need to really get into this stuff. But I had the deep feeling that Adobe had a master plan to let us Flash developers down and let “real” C++ or better Assembler programmers take over our beloved flash platform. Then there was AIR and everything changed. I fell in love with AIR from the first minute and only had one problem with it. I had the feeling that the new tool Adobe was giving us was not feature complete. All the apps I wanted to build needed something that was not covered by the new API. After some hours thinking about getting frustrated I realized that the frightening ByteArray class could be part of the solution.


In our normal live we deal a lot with numbers. The number system we are most familiar with is the decimal number system. The decimal number system is a base 10 numeral system which basically means that we know ten symbols (0-9) called digits to represent numbers. When working with binary data we still deal with numbers but the symbols we have available are less. The binary system only knows two symbols 0`s and 1`s to represent any number. In the binary world those symbols are called Bits. If you`re are not familiar with the binary system you may ask how it`s possible to represent any possible number with just 0`s and 1`s. Counting in binary is very much similar to counting in decimal. In decimal you start counting with the 9 symbols you have like so:

001, 002, 003, 004, 005, 006, 007, 008, 009

When all symbols are used you add one digit to the left and reset the one before to zero. Now you restart incrementing those values.

010, 011, 012, 013, 014, 015, 016, 017, 018, 019, 020 and so on.

This is exactly the same in the binary world only that counting up is faster because we only have two symbols. So it goes like this:

0000, 0001, 0010, 0011, 0100, 0101, 0110, 0111 …


The symbols 0 and 1 that are used in the binary system are called bits in the computer world. A bit is the smallest information a computer can work with. Most of the time when you deal with binary data you will not deal with single bits but rather with collections of bits. Those collections are called a word. Those words can consist of different numbers of bits and the smallest collection used is a byte which consists of 8 bits. Because a Byte has 8 Bits it can describe integers between 0 and 255. There are two ways how to group Bits into a byte. The most common one is called Big-Endian were you start counting on the right site. So the Bits on the right site will carry lower values and the more Bits you go to the left the higher the values. That`s why the Bits on the right are called the least-significant Bits and the Bits on the left are called the most-significant Bits. As said earlier this way of ordering Bits into a Byte is called Big-Endian. The opposite of this is called Little-Endian were the least-significant Bits are on the left and the most-significant Bits are on the right.


In the last paragraph we said that a byte can represent integers with a value between 0-255. Often however we do not treat words as a representation of a number but rather as a container for Bits, were groups of Bits inside this container can carry their own information. Imagine for example you want to store the numbers 15 and 12. To do this you can use two Bytes like this.

00001111 = 15

00001100 = 12

We can see that in those two Bytes the most-significant Bits are not used. In this example 4 Bits for each Number are just wasted. To store our two numbers more efficiently we could rather store both numbers in one Byte like this:

1100 1111

The one who later analyses the Byte just needs to know that the first and the last 4 Bits each represent a Number.

When information is stored into a word like this we speak of a packed word. In order to analyze the content of a packed word we need to have tools to extract individual Bits from a word. When you check out the ByteArray class of the Flash Player you`ll see that the smallest information you can get is a Byte (ByteArray.readByte()). I order to analyze the individual Bits of a word bitwise operations will become a handy tool.

To Be Continued…

Article Series: Bits and Bytes with AIR

As promised a little bit fast last week I want to start a series of articles about manipulating Bits and Bytes with AIR.

This is quite a hard task for me because:
– I’m not used to write
– I’m not used to write in English
– the whole Byte/Bits stuff is new to me
– I’m lazy and announcing a series of articles is kind of a pressure

Anyway I decided to do it because I think the whole topic really has a lot of potential for AIR and Flex and I hope it can be useful for people like me that have never before worked on such a low level with files. And this is also a chance for me to archive all the knowledge I’ve gain over the last few months.
On the other hand this is an excuse for not open sourcing the code for RichFLV and RichMp3 so far. I hope that this series will enable you to write your own implementation.

This could all be a bit boring for real computer geeks and i even cannot promise that these articles aren`t full of mistakes but i hope that your comments will turn it into something useful.

I would like to write this in the form of a book chapter and I will attach a PDF at the end of each new article that will contain all updates and corrections:
Here is a brief overview of what I want to cover:


In the end we should end up with something like RichMp3.
I hope to write a chapter once a week but no promise on this.
I will upload the introduction in the next hour. All comments, critics and corrections are very welcome!

RichFLV now with autoupdate and drag`n drop

I`ve build in some more AIR specific features into RichFLV and also worked on the SWF export that now includes sound export.
Until now you could export your flv as an SWF but without the sound. I now managed to implement the SoundStreamHead and SoundStreamBlock Tags
from the SWF Specification. With some flvs there are still problems but most of the time it works fine. Don`t wonder if the SWF export now takes a bit longer i will optimize that later.

I`ve also implemented an autoupdate feature. When RichFLV is started it checks automatically if updates are available. If it finds an update it will show you a dialog that tells you something about
the changes in the new version and allows to auto update the app with one click. You can also manually check for updates by clicking the “Check for updates” item in the “About” menu.



One other small feature i`ve included is that if you have a video playing you can drag the video at any point to your desktop and it will make a screenshot from that position on your desktop (as a PNG).


Get the Update:

Last day at work!

Today i celebrate my last day at ArgonautenG2. It was a great time but now it`s time to move on and concentrate on Flex/AIR projects.
From now on i go on as a freelancer in the hope to be able to pick up more Flex/AIR related work. I also plan to write more in depth articles here.
Next week i want to start a series about the ByteArray stuff i used for RichFLV and RichMp3.

I`m fully booked for the next 5 months but if you have any interesting Flex/AIR projects – drop me a mail benz (at)

Read/Write ID3 Tags with AIR

I found some time to improve my MP3 library. Now it allows to read and write! ID3v2 Tags.
I`ve not implemented everything but you can read basic information and edit it. You can even select a jpeg or png file that will be embedded into the mp3.
You can still trim the mp3 with the timeline. ByteArray and AIR kicks ass!

Check it out here (You`ll need the Adobe AIR Runtime)

Sources will be released as soon as i find the time to clean up the code and implement some more functionality.