C语言,将 2 位 BCD 值转换为整数

请问这个应该要怎么解决?按照要求来写代码,在“PUT YOUR CODE HERE”写内容,例子旁边的#只是他的解释,蟹蟹大lao。题目如下。

img

img

img

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <assert.h>
int bcd(int bcd_value);
int main(int argc, char *argv[]) {
    for (int arg = 1; arg < argc; arg++) {
        long l = strtol(argv[arg], NULL, 0);
        assert(l >= 0 && l <= 0x0909);
        int bcd_value = l;
        printf("%d\n", bcd(bcd_value));
    }
    return 0;
}
// given a  BCD encoded value between 0 .. 99
// return corresponding integer
int bcd(int bcd_value) {
    // PUT YOUR CODE HERE
    return 0;
}
 

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <assert.h>
int bcd(int bcd_value);
int main(int argc, char *argv[])
{
    for (int arg = 1; arg < argc; arg++)
    {
        long l = strtol(argv[arg], NULL, 0);
        assert(l >= 0 && l <= 0x0909);
        int bcd_value = l;
        printf("%d\n", bcd(bcd_value));
    }
    return 0;
}
// given a  BCD encoded value between 0 .. 99
// return corresponding integer
int bcd(int bcd_value)
{

    int a = 0, b = 1;
    int n;
    while (bcd_value)
    {
        n = 0xF & bcd_value;
        bcd_value = bcd_value >> 4;
        a = a + b * n;
        b = b * 10;
    }

    return a;
}