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

  • Home
  • SEARCH
  • 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 8206813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:48:00+00:00 2026-06-07T08:48:00+00:00

Possible Duplicate: Converting an int into a 4 byte char array (C) Using the

  • 0

Possible Duplicate:
Converting an int into a 4 byte char array (C)

Using the Dynamic C program (the language is C), I am trying to convert an int into an array of bytes 4 places long. So far I have looked online and I have found a few examples. However, none seem to work for me. I have had an ongoing problem where the correct byte numbers are printed, but they are repeated twice for some reason. I have provided the code below:

void main(){
 int a=1379;
 int i=0;
 unsigned char value [4];

value[3] = (byte) (a & (0xFF));
value[2] = (byte) ((a >> 8) & 0xFF);
value[1] = (byte) ((a >> 16) & 0xFF);
value[0] = (byte) ((a >> 24) & 0xFF);
//convert int values to bytes by placing them in a char buffer

for(i=0;i<4;i++){
 printf("%d",value[i]);
 printf(", ");
 }
printf("\n");
}

For example, with this value the program prints “5, 99, 5, 99,” when it should print “0, 0, 5, 99”. Thank you for your help.

  • 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-07T08:48:03+00:00Added an answer on June 7, 2026 at 8:48 am

    It’s almost certainly the case that “Dynamic C” is an implementation with an int of 16 bits, which is perfectly “legal” for C. If the int is 16 bits, any shift over 16 bits is modulo-16, so the second two shifts duplicate the first two.

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

Sidebar

Related Questions

Possible Duplicate: converting pixels to dp in android I'm trying to convert pixels to
Possible Duplicate: Byte array in objective-c Am converting some Java code to Objective-C and
Possible Duplicate: Converting string to int in java I am trying to write a
Possible Duplicate: Converting an uint64 into a (full)hex string, C++ I am trying to
Possible Duplicate: Converting C “FOR” loop to Delphi I'm trying to convert a C++
Possible Duplicate: Converting XML to JSON using Python? I'm doing some work on App
Possible Duplicate: Alternative to itoa() for converting integer to string C++? How to convert
Possible Duplicate: Porting a C array declaration to Delphi I'm converting a C code
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: Char to int conversion in C. I remember learning in a course

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.