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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:14:10+00:00 2026-06-14T10:14:10+00:00

I scan through the byte representation of an int variable and get somewhat unexpected

  • 0

I scan through the byte representation of an int variable and get somewhat unexpected result.

If I do

int a = 127;
cout << (unsigned int) *((char *)&a);

I get 127 as expected. If I do

int a = 256;
cout << (unsigned int) *((char *)&a + 1);

I get 1 as expected. But if I do

int a = 128;
cout << (unsigned int) *((char *)&a);

I have 4294967168 which is, well… quite fancy.

The question is: is there a way to get 128 when looking at first byte of an int variable which value is 128?

  • 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-14T10:14:11+00:00Added an answer on June 14, 2026 at 10:14 am

    For the same reason that (unsigned int)(char)128 is 4294967168: char is signed by default on most commonly used systems. 128 cannot fit in a signed 8-bit quantity, so when you cast it to char, you get -128 (0x80 in hex).

    Then, when you cast -128 to an unsigned int, you get 232 – 128, which is 4294967168.

    If you want to get +128, then use an unsigned char instead of char.

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

Sidebar

Related Questions

I am trying to scan through an NSMutableArray and remove all 0's. (They are
I am working on a project requiring me to scan through a large number
I used ReconstructMe to scan my first half body (arm and head). The result
I currently scan packages for DAOs and services using Spring 3.1 & Hibernate 4
I need to scan through a document and accumulate the output of different functions
Here is an excerpt from the html I want to scan through. <div class=text>
How can I scan through a file which contains email addresses that are separated
Does anyone know of a Windows app that can scan through a directory and
While recursive scans are commonly use to scan through nested objects / data. It
How would it be possible to do the following: Scan through an html page

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.