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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:50:56+00:00 2026-05-25T11:50:56+00:00

long int FinalValue; char a,b,c,d; a=0x1; b=0x2; c=0x3; d=0x4; FinalValue |= (long)a; FinalValue <<=

  • 0
long int FinalValue;
char a,b,c,d;

a=0x1;
b=0x2;
c=0x3;
d=0x4;

FinalValue |=  (long)a;
FinalValue <<= 0x8;
FinalValue |=  (long)b;
FinalValue <<= 0x8;
FinalValue |=  (long)c;
FinalValue <<= 0x8;
FinalValue |=  (long)d;


Printf("%d, %d, %d, %d", a,b,c,d);
Printf("FinalValue = %ld"FinalValue);

Output obtained:
1 2 3 4
FinalValue = 0x05020304

Expected Output:
1 2 3 4
FinalValue = 0x01020304

When the above code is executed with different inputs (for a,b,c,d), the output obtained in MSB of final value is: 0x(a|d)bcd (in the above example 0x1 or with 0x4, to obtaine 0x5)

Why is the MSB byte is getting ORed with LSB byte?

  • 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-25T11:50:56+00:00Added an answer on May 25, 2026 at 11:50 am
    1. First initialize FinalValue to 0, uninitialized local (automatic) variables contain garbage.

    2. change Printf("FinalValue = %ld"FinalValue); to printf("FinalValue = %ld", FinalValue); , add the comma.

    3. What is Printf ? You probably meant printf .

    4. You want output in hex ? Use %lx . printf("FinalValue = %lx", FinalValue);

    5. Make FinalValue unsigned and then shift. Shifting of the signed bit of a signed number is implementation dependent.

    UPDATE: added point 5

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

Sidebar

Related Questions

Compiling this lines long int sz; char tmpret[128]; //take substring of c, translate in
I need a Hash function with a 256bit output (as long int). First I
typedef long int INT; typedef unsigned char byte; #define MAX_CITIES (INT)2.7e6 #define MAX_LEN (int)1e6
Suppose I have one long long int and want to take its bits and
I managed to get a unsigned long int octets-representation (BE) by reading IPv4 methods,
symbol.c: In function 'symbol_FPrint': symbol.c:1209: warning: format '%ld' expects type 'long int', but argument
#include <stdio.h> int main() { unsigned long long int num = 285212672; //FYI: fits
#include <vector> std::vector<long int> as; long int a(size_t n){ if(n==1) return 1; if(n==2) return
#include<stdio.h> #include<time.h> int main() { clock_t start; double d; long int n,i,j; scanf(%ld,&n); n=100000;
Short problem: #include <iostream> using namespace std; int main() { double **T; long int

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.