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 8308229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:44:26+00:00 2026-06-08T18:44:26+00:00

im Converting a uint32_t hex number into uint32_t BCD number. and will do the

  • 0

im Converting a uint32_t hex number into uint32_t BCD number. and will do the same to uint64 hex to BCD…

i have this from a uint16

uint16_t CvtBcd(uint16_t HexNumber)
{
  return ((HexNumber/ 10) << 4) | (HexNumber% 10); 
}

edit:

I’m going to use it as an external code to be used for a bigger program.

// Converts a uint32_t hex number into uint32_t BCD number.
extern uint32_t Cvt32Bcd(uint32_t HexNumber)
{
  return ((HexNumber/10) << 8 | (HexNumber % 10));
}
  • 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-08T18:44:27+00:00Added an answer on June 8, 2026 at 6:44 pm

    In a binary coded decimal representation, you need four bits per decimal digit, thus you cannot convert all (unsigned) integers to a BCD representation of the same size, usually you need a larger type for that. Ignoring that problem, an algorithm to convert an unsigned integer of whatever size to its BCD representation is

    uintN_t convert_to_BCD(uintN_t n) {
        uintN_t bcd = 0;
        int shift = 0;
        while(n) {
            bcd |= (n % 10) << shift;
            n /= 10;
            shift += 4;
        }
        return bcd;
    }
    

    To avoid overflow, make the return type larger than the argument type, but that doesn’t work for the largest available input type, of course. You could then use an array of unsigned char to hold the digits, or a struct containing two uintN_ts to hold the result.

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

Sidebar

Related Questions

Converting from Django, I'm used to doing something like this: {% if not var1
Im converting this simple program from vb to c# it updates, displays, create and
Converting a project from Codeblocks to Visual Studio I encountered this puzzling error from
Converting a database of people and addresses from ALL CAPS to Title Case will
Converting an old program into an ASP.NET c# site. I have a table full
Converting json to oher type should be easy. From the Play! documentation : var
Converting to ODB.NET from System.Data.OracleClient and need help converting my connection string. Here is
For converting a integer into an enum (out of a json file), I declared
Currently working with converting SQLException error messages into messages that are more useful for
Any tools to convert C code into Java code? I am interested in converting

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.