Decimal encoder for BCD
Look up something called a priority encoder.

However, a function like this is rarely needed in isolation.  In that case, this is something you do in firmware in the microcontroller that is already there for other reasons.

Even with no other reason, a microcontroller might be a good idea if bouncing of the buttons would cause problems.  Consider what happens while a button bounces.  The output code could possibly appear to go thru lots of states as each line toggles between 0 and its value to represent that button.