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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:34:24+00:00 2026-05-26T12:34:24+00:00

I think my understanding of bytes arrays and char arrays is causing me some

  • 0

I think my understanding of bytes arrays and char arrays is causing me some issues, here is my problem:

I have an application that pulls messages from Websphere MQ and sends them onto a target system.

A MQ message has a MQBYTE24 (byte array 24 essentially) that represents the MSGID of the message. My goal is to convert this to a hexidecimal string.

On the WMQ explorer on my Linux box message 1 in the queue has a message identifier of “AMQ QM01” (at least that it what it looks like), and the bytes are below as displayed in the explorer:

00000   41 4D 51 20 51 4D 30 31--20 20 20 20 20 20 20 20  |AMQ QM01        |
00010   BD F4 A8 4E A2 A3 06 20--                         |...N...         |

Now when my code runs I pick up that same message id and try convert it to a hex string.

The exact message id while debugging is:

AMQ QM01 \275\364\250N\242\243\006

And after running through my conversion (code below) i get:

414D5120514D30312020202020202020FFFFFF4EFFFF6

As you can see it is slightly different to the one that the WMQ Explorer shows, any idea what i am doing wrong here?

I assume it is me converting from the MQBYTE24 to char….something is going wrong there…

Below is a small sample program that produces the “wrong result”…..i assune i must use a byte array instead of char?

The output for the following is:

Result: 414D5120514D30312020202020202020FFFFFF4EFFFF6

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(){   
    char name[41]="AMQ QM01        \275\364\250N\242\243\006";
    char buffer[82]="";
    char *pbuffer = buffer;
    FILE *fp_1;
    FILE *fp_2;
    int size;
    char *buffer_1 = NULL;
    char *buffer_2 = NULL;

    int rc = convertStrToHex(buffer, name);
    printf( "Result: %s\n", pbuffer ); 
    }
    return 0;
}

int convertStrToHex(char *buffer, char str[10]){
    int len = strlen(str);
    int i;

    for( i = 0; i < len ;i++ ){
        sprintf(buffer, "%X", str[i]);
        buffer +=2;
    };
}

Thanks for the help 🙂

Lynton

  • 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-26T12:34:25+00:00Added an answer on May 26, 2026 at 12:34 pm

    As several other answers already point out, you need to cast the characters to unsigned char to avoid their being padded with FF to fill a 32-bit int’s worth of bytes. But there’s actually another issue: that lone number 6 at the end will only print as one character in the output. You want each character to take up exactly two positions, so you need a zero-padded field specifier. Putting it all together, you get

    sprintf(buffer, "%02X", (unsigned char)str[i]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I have a basic understanding of this, but am hoping that someone
I think I have a problem in understanding the proper way of using MVC.
I think i have a basic problem in understanding the dojo toolkit. Well I
I think I have a basic understanding of REST, but something I'm stuck on
I've recently encountered what I think is a false-sharing problem in my application, and
Some streams in c# appear to have a direction in that they are meant
I am having a problem understanding why this part of my code is causing
I'm not sure how to describe this best. But I have a problem understanding
i don't think im understanding this correctly, but how do i give users a
I think this question is really about my understanding of Garbage collection and variable

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.