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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:43:38+00:00 2026-06-09T20:43:38+00:00

I am trying to combine two 8-bit number to an unsigned int but no

  • 0

I am trying to combine two 8-bit number to an unsigned int but no matter what type casting I use, the result is still signed number. The code is complied using CodeWarrior 10.1 for freescale micro processor MC9S08LH64.

Things I tried that did not work
– shift and add the two 8bits number then type cast them to be unsigned int at every step.
– union/struct to combine the two 8-bit type cast them and the result number to unsigned int.
– use unsigned int pointer (code below)

unsigned int acquire_sensor_voltage_internal_adc()
{ //this is internal ADC
     unsigned int result;
     unsigned int* data_ptr;
     char print_buffer [50];
     int_convert cvt;
    //internal adc collecting counts of input voltage
    //______________________________________________

    //writing to ADCSC1A initiate the conversion sequence
    ADCSC1A= 0x09;
    while(!ADCSC1A_COCOA){}

    cvt.parts.p0 = ADCRHA;
    cvt.parts.p1 = ADCRLA;
    data_ptr = &cvt.int_number;
    result = (unsigned int)*data_ptr;

    sprintf(print_buffer,"here!!!>>>>>>>%d\r\n",result);
    serial_sendString(print_buffer,strlen(print_buffer));
    //_______________________________________________
    return (unsigned int) result;
}

//definition of int_convert from.h file
typedef union{
unsigned int int_number;
struct{
    unsigned char p0;
    unsigned char p1;
}parts;
}int_convert;
  • 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-09T20:43:39+00:00Added an answer on June 9, 2026 at 8:43 pm

    You could try:

    result = ((unsigned)ADCRHA) << 8 | (unsigned)ADCRHB;
    

    And then use the correct format specifier %u instead of %d.

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

Sidebar

Related Questions

I am trying to use array_combine to combine two multi-dimensional arrays, but somehow not
I'm trying to combine two separate javascript functions' outputs but each function is on
I'm trying to combine info from two different logs into a single query, but
I am trying to combine two SortedDictionaries , change the result to a List<KeyvaluePair<string,string>>
I am trying to combine two repos but I get error repository is unrelated..
I'm trying to combine two or more xml files for better use. Let's say
i am trying to combine two arrays with their relations but cant do exatly.
I have a strange case of trying to combine two pseudoclasses: :not and :nth-of-type()
I'm trying to merge\combine two datatables. I've looked at various examples and answers but
I'm trying to combine code on two branches with the 'git merge' command, but

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.