Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8337709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:22:39+00:00 2026-06-09T04:22:39+00:00

I am doing bug fixing on a old c code in our system (

  • 0

I am doing bug fixing on a old c code in our system ( strangely enough, it’s not standard c. It is not compiled by gcc ). I come to this code which seems to be converting a string to binary code in unsigned char format. The logic puzzle me ( bold part ). Does this make any sense to you guys?

I need to understand this code because I have to copy this and reuse it on another string whose length is not 13 but 11.

char l_call_dest_no[25];
int l_loop_cnt;
unsigned char l_bcd_byte;
unsigned char l_call_dest_no_in_bcd[13];

...some other code as input...

    for (l_loop_cnt = 0; l_loop_cnt < 13; l_loop_cnt++)
            {
                l_bcd_byte = '\0';
                switch (l_call_dest_no[l_loop_cnt * 2])
                {
                    case '0':
                    case '1':
                    case '2':
                    case '3':
                    case '4':
                    case '5':
                    case '6':
                    case '7':
                    case '8':
                    case '9':
                        l_bcd_byte = (l_call_dest_no[l_loop_cnt * 2] - 48) * 16;
                        break;
                    case 'A':
                        l_bcd_byte = 10 * 16;
                        break;
                    case 'B':
                        l_bcd_byte = 11 * 16;
                        break;
                    case 'C':
                        l_bcd_byte = 12 * 16;
                        break;
                    case 'D':
                        l_bcd_byte = 13 * 16;
                        break;
                    case 'E':
                        l_bcd_byte = 14 * 16;
                        break;
                    case 'F':
                    case ' ':
                        l_bcd_byte = 15 * 16;
                        break;
                    default:
                        printf("*** invalid call destination number ***\n");
                        return_status = FAILURE;
                        break;
                }

                if (l_loop_cnt < 12)
                {
                    switch (l_call_dest_no[l_loop_cnt * 2 + 1])
                    {
                        case '0':
                        case '1':
                        case '2':
                        case '3':
                        case '4':
                        case '5':
                        case '6':
                        case '7':
                        case '8':
                        case '9':
                            l_bcd_byte = l_bcd_byte + (l_call_dest_no[l_loop_cnt * 2 + 1] - 48) ;
                            break;
                        case 'A':
                            l_bcd_byte = l_bcd_byte + 10;
                            break;
                        case 'B':
                            l_bcd_byte = l_bcd_byte + 11;
                            break;
                        case 'C':
                            l_bcd_byte = l_bcd_byte + 12;
                            break;
                        case 'D':
                            l_bcd_byte = l_bcd_byte + 13;
                            break;
                        case 'E':
                            l_bcd_byte = l_bcd_byte + 14;
                            break;
                        case 'F':
                        case ' ':
                            l_bcd_byte = l_bcd_byte + 15;
                            break;
                        default:
                            printf("*** invalid call destination number ***\n");
                            return_status = FAILURE;
                            break;
                    }
                }
                else
                    l_bcd_byte = l_bcd_byte + 15;

                if (l_bcd_byte == 255)
                    l_call_dest_no_in_bcd[l_loop_cnt] = '\0';
                else
                {
                    l_call_dest_no_in_bcd[l_loop_cnt] = l_bcd_byte;
                        l_call_dest_no_bcd_length++;
                }
            }   
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:22:41+00:00Added an answer on June 9, 2026 at 4:22 am

    The code converts strings containing hexadecimal (e.g. "002A40FF160AD") to an array of bytes containing the values in raw binary (e.g. {0x00, 0x2A, 0x40, 0xFF, 0x16, 0x0A, 0xDF}). The function has a few gotchas:

    • Strangely enough, the string length isn’t even, so an additional ‘F’ is implied to be at the end of the string. (the else l_bcd_byte = l_bcd_byte + 15;).
    • Additional oddity is that "FF" is converted to 0x00.
    • Both 'F' and ' ' (a space) are treated as an 'F'
    • The function works also as a string to packed-decimal (BCD) converter, because packed decimals look like hexadecimal numbers using only digits 0-9 (e.g. 15 in decimal is 0x15 in packed decimal). The final F complicates this functionality, though.

    EDIT

    The final F makes packed-decimal format actually easier to use: an F at the end of a packed-decimal number means that the number is unsigned.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not sure if this is a MMA bug or me doing something wrong. Consider
Not sure if this is a bug but it's not doing what I expect.
I think there is a bug in this filter_var or maybe I'm doing something
I have been doing some tests (to replace old code) with the __invoke magic
Is this a bug in Rails' asset? I don't see what I am doing
Is this a Boost bug or am I doing something wrong? #include <map> #include
Sometimes, when we're doing small changes to our web apps, e.g. bug fixes, we
after doing some test-code for this link : Is it safe to call temporary
I must be doing something wrong... Or this may be a bug in YAJL,
I wonder if I'm doing something wrong or if this is a compiler bug.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.