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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:58:15+00:00 2026-05-29T15:58:15+00:00

I have a unsigned int that was converted to a signed char like this

  • 0

I have a unsigned int that was converted to a signed char like this

  unsigned int b = 128;
  char a[4];    

  a[0] = b >> 24;
  a[1] = b >> 16;
  a[2] = b >> 8;
  a[3] = b >> 0;

Without knowing what value of b is, can I get back the number? The method below fails for numbers greater than 128. It seems like there is some ambiguity to getting the number back from the array.

  unsigned int c = 0;  
  c += a[0] << 24;
  c += a[1] << 16;
  c += a[2] << 8;
  c += a[3];

  cout<<c<<endl;
  • 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-05-29T15:58:18+00:00Added an answer on May 29, 2026 at 3:58 pm
    unsigned int c = ((a[0] << 24) & 0xFF000000U)
                   | ((a[1] << 16) & 0x00FF0000U)
                   | ((a[2] <<  8) & 0x0000FF00U)
                   | ( a[3]        & 0x000000FFU);
    

    or

    unsigned int c = unsigned(a[0]) << 24
                   | unsigned(a[1]) << 16
                   | unsigned(a[2]) <<  8
                   | unsigned(a[3]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have an unsigned char * that looks (after printf) like this (it's
I have some code that looks like: template<unsigned int A, unsigned int B> int
I have a small sample function: #define VALUE 0 int test(unsigned char x) {
I have an unsigned int variable and it can only have the values of
I have the following code int ParseData(unsigned char *packet, int len) { struct ethhdr
I have this table CREATE TABLE `codes` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
I have the code: unsigned int length = strlen(somestring); I'm compiling with the warning
Suppose I have the following C code. unsigned int u = 1234; int i
I have the following table in MySQL (version 5): id int(10) UNSIGNED No auto_increment
I have a members table in MySQL CREATE TABLE `members` ( `id` int(10) unsigned

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.