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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:51:57+00:00 2026-06-16T04:51:57+00:00

Possible Duplicate: Store an int in a char array? i want to load 4

  • 0

Possible Duplicate:
Store an int in a char array?

i want to load 4 8-bit unsigned char to 32-bit integer. And store 32 bit integer to unsigned char pointer. How is this possible?Example usage below;

int 32bitint1= 0xff000000 | (uchar1<<16) | (uchar2<<8) | uchar3;
int 32bitint2= 0xff000000 | (uchar4<<16) | (uchar5<<8) | uchar6;
//then this 32-bit integer to uchar pointer;
ucharpointer[0] = 32bitint1;
ucharpointer[4] = 32bitint2;//is this possible?or how
  • 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-16T04:51:58+00:00Added an answer on June 16, 2026 at 4:51 am

    Store: (store 4 chars into an unsigned int)

    int store(uint32_t * reg, unsigned char c[4])
    {
        *reg = 0;
            for(int i=0;i<4;i++)
            {
                *reg = (*reg<<8) | c[i];
            }
            return 0;
    }
    

    Load: (load 4 chars from an unsigned int)

    int load(uint32_t * reg, unsigned char c[4])
    {
            for(int i=0;i<4;i++)
            {
                c[i] = *reg;
                *reg = *reg>>8;
            }
            return 0;
    }
    

    Usage example:

    int main ()
    {
        unsigned char c[4] = {'a','b','c','d'};
        uint32_t reg;
    
        printf("%c",c[0]);  //it prints 'a'
        store(&reg,c);   
    
        c[0] = 'e';
        printf("%c",c[0]);  //it prints 'e'
    
        load(&reg,c);     //load
        printf("%c",c[0]);  //it prints 'a' again
    
        return 0;
    }
    

    If you don’t want to reload them into a char array, but to access them by a char pointer, then here’s an example:

    int main (int argc, char const *argv[])
    {
        unsigned char c[4] = {'a','b','c','d'};
        uint32_t reg;
        store(&reg,c);
    
        unsigned char *cpointer = (unsigned char *) &reg;
    
        for(int i=0;i<4;i++)
        {
            printf("%c",cpointer[i]);  //access the 4 chars by a char pointer
        }
        return 0;
    }
    

    Please note that the you will get an output ‘dcba’ in this way, as the memory address are made in the reverse order.

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

Sidebar

Related Questions

Possible Duplicate: Is array name a pointer in C? #include <stdlib.h> int main(int argc,
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: separate the ids and store in two different array String response=@ hr
Possible Duplicate: C++ convert int and string to char* Hello, i am making a
Possible Duplicate: Best way to detect integer overflow in C/C++ I was asked this
Possible Duplicate: How does dereferencing of a function pointer happen? void myprint(char* x) {
Possible Duplicate: How to store an IP in mySQL I want to get the
Possible Duplicate: Using Dynamic Memory allocation for arrays I originally had this program store
Possible duplicate: How can i give app store link in my apps before approving
Possible Duplicate: Problem with processing individual strings stored in an array of pointers to

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.