please explain me how this algorithm works ? http://vhdlguru.blogspot.com/2010/04/8-bit-binary-to-bcd-converter-double.html
The link to the algorithm on wikipedia was pretty helpful.
BCD is binary coded decimal. Meaning it is hexadecimal but only the digits 0-9 are used.
The algorithm does a bunch of left shifts by one. Each left shift by one is the equivalent of a multiply by two. When you multiply a hexadecimal digit by two, it will carry to the next digit if it is eight or higher. With BCD, you want it to carry if it is 5 or higher, so it behaves like decimal.
Before each shift, each BCD digit is tested. If it is above 4, it is increased by 3. The digit must be under A to be valid BCD so this will not carry. When the shift occurs, the 3 will magically disappear back into the BCD.
The values 0,1,2,3,4 are obvious. Multiplying by two just works. The values 5,6,7,8,9 are the tricky bits. They should map to 10,12,14,16,18 in decimal. In hexadecimal they map to A,C,E,10,12 which all happen to be off by 6 from the desired values, which is 3*2 which is why 3 is added before the digits are multiplied by 2.
Since there are as many left shifts as there were input bits, all the bits have been shifted into the output area. Since each BCD digit is tested at each shift, any hexadecimal digits are filtered out.