I have a basic doubt here and it concerns programming.
I wrote a program that emulates JPEG compression. Now after performing Huffman compression, I get codes of variable lengths.
If I place them one after another, how is the decoder going to decode the resulting bitstream? How will it know where one code ends and the next one begins?

Eg: "a" is coded as 0101
"b" is coded as 11

So, "aba" = 0101110101.....right?

How is this taken care of? How will it know that the first 4 bits are "a" and the next two are "b" , etc?
One way I can think of is that, since each code is uniquely decodable, if i keep looking up a table after every bit i read .. I will know when I have read a code. But is there a better way to do this?

PS:In my program I just left shifted them and stuffed bits to make them all 16bits in length. SInce this was only for simulation, I didnt care much. But in terms of rate it was really bad.

Thanks !