Avoid buffer overrun in bd2str caused by sign extension

Use uint8_t to avoid sign extension as char's may be signed.
As a further safeguard, use snprintf()

Change-Id: I44b2876f3c61031412592e4a738dc6d544e47419