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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:55:33+00:00 2026-05-14T08:55:33+00:00

unsigned short s; s = 0xffff; int i = s; How does the extension

  • 0
unsigned short s;
s = 0xffff;
int i = s;

How does the extension work here? 2 larger order bytes are added, but I’m confused whether 1’s or 0’s are extended there. This is probably platform dependent so let’s focus on what Unix does. Would the two bigger order bytes of the int be filled with 1’s or 0’s, and why?

Basically, does the computer know that s is unsigned, and correctly assign 0’s to the higher order bits of the int? So i is now 0x0000ffff? Or since ints are default signed in unix does it take the signed bit from s (a 1) and copy that to the higher order bytes?

  • 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-14T08:55:33+00:00Added an answer on May 14, 2026 at 8:55 am

    No, an unsigned value is never sign-extended. Upcasting will always pad such a value with zeroes.

    More precisely, the unsigned variable represents a particular number, and it will still represent the same number after a cast, provided that is possible in the new format.

    Hexadecimal or no, C (although not C99) and C++ are designed to work in the absence of bits, eg with base-10 numerics.

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

Sidebar

Related Questions

That is, why does unsigned short var= L'ÿ' work, but unsigned short var[]= Lÿ;
I'm initializing an unsigned short int with a = 0xff (all bits are set).
So here's a snippet of my code: struct dv_nexthop_cost_pair { unsigned short nexthop; unsigned
for example, does: wchar_t x; translate to: unsigned short x;
struct Record { char Surname[20]; char Initial; unsigned short int Gender; //0 = male
What I know about unsigned numerics (unsigned short, int and longs), that It contains
Given a function prototype, and a type definition: int my_function(unsigned short x); typedef unsigned
Let's we have std::vector <std::vector <unsigned short int>> face; face.resize(nElm); Its OK to resize()
I would like to cast unsigned int (32bit) A to unsigned short int (16bit)
I know the difference in memory usage between byte, unsigned short, and integer, but

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.