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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:37:34+00:00 2026-06-10T15:37:34+00:00

I have a unsigned char array[248]; filled with bytes. Like 2F AF FF 00

  • 0

I have a unsigned char array[248]; filled with bytes. Like 2F AF FF 00 EB AB CD EF …..
This Array is my Byte Stream which I store my Data from the UART (RS232) as a Buffer.

Now I want to convert the bytes back to my uint16’s and int32’s.

In C# I used the BitConverter Class to do this. e.g:

byte[] Array = { 0A, AB, CD, 25 };
int myint1 = BitConverter.ToInt32(bytes, 0);
int myint2 = BitConverter.ToInt32(bytes, 4);
int myint3 = BitConverter.ToInt32(bytes, 8);
int myint4 = BitConverter.ToInt32(bytes, 12);
//...
enter code here
Console.WriteLine("int: {0}", myint1); //output Data...

Is there a similiar Function in C ? (no .net , I use the KEIL compiler because code is running on a microcontroller)

With Regards
Sam

  • 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-10T15:37:35+00:00Added an answer on June 10, 2026 at 3:37 pm

    Yes there is. Assume your bytes are in:

    uint8_t bytes[N] = { /* whatever */ };
    

    We know that, a 16 bit integer is just two 8 bit integers concatenated, i.e. one has a multiple of 256 or alternatively is shifted by 8:

    uint16_t sixteen[N/2];
    
    for (i = 0; i < N; i += 2)
        sixteen[i/2] = bytes[i] | (uint16_t)bytes[i+1] << 8;
                 // assuming you have read your bytes little-endian
    

    Similarly for 32 bits:

    uint32_t thirty_two[N/4];
    
    for (i = 0; i < N; i += 4)
        thirty_two[i/4] = bytes[i] | (uint32_t)bytes[i+1] << 8
            | (uint32_t)bytes[i+2] << 16 | (uint32_t)bytes[i+3] << 24;
                 // same assumption
    

    If the bytes are read big-endian, of course you reverse the order:

    bytes[i+1] | (uint16_t)bytes[i] << 8
    

    and

    bytes[i+3] | (uint32_t)bytes[i+2] << 8
        | (uint32_t)bytes[i+1] << 16 | (uint32_t)bytes[i] << 24
    

    Note that there’s a difference between the endian-ness in the stored integer and the endian-ness of the running architecture. The endian-ness referred to in this answer is of the stored integer, i.e., the contents of bytes. The solutions are independent of the endian-ness of the running architecture since endian-ness is taken care of when shifting.

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

Sidebar

Related Questions

I have an array that is like this: unsigned char array[] = {'\xc0', '\x3f',
I have a class like this: class Object { public: unsigned char data[8]; //
I have this array: unsigned char* data = CGBitmapContextGetData(cgctx); then I tried to get
If I have a struct like this: typedef struct { unsigned char c1; unsigned
I have an std::vector<unsigned char> with binary data in. I just would like to
I have a byte (unsigned char) array. How to draw it using QPainter?
I have 2-dimensional array like below. unsigned char myArray[][48] = { {0xfc,0x94,0x88,0x48,0x5f,0xa4,0x9a,0xfb,0x6e,0xf8,0xcd,0x01,0x47,0x64,0x03,0xd0,0x1f,0xb8,0xa3,0x85,0x84,0xa9,0x4a,0xc4,0x9e,0xea,0x26,0x09,0x62,0x96,0x91,0xa6}, {0xa9,0xc5,0x9a,0xb3,0x09,0x38,0x15,0xb3,0x22,0xb3,0x07,0x21,0x3e,0x39,0x35,0xc6,0x69,0x6e,0xf3,0x64,0xb0,0x0a,0x4c,0xcb,0x77,0xff,0x76,0x3c,0x37,0xf3,0x99,0x96}, {0x24,0x4d,0xc0,0x45,0xe0,0x50,0x1f,0x72,0x0f,0xb0,0xcc,0xb9,0xc6,0x72,0xa9,0x5a,0xf3,0x5a,0xd9,0xe2,0xc3,0x44,0xd9,0x25,0xf3,0x12,0x6a,0x0c,0x37,0x6a,0x3f,0xb6},
I have a big lump of binary data in a char[] array which I
I have a double converted to a unsigned char array. For example for value
I have a program structure like following : int firstFunction(unsigned char *firstValue, int s,

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.