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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:44:04+00:00 2026-05-28T07:44:04+00:00

I have a datatype that’s more or less a character array. Each space in

  • 0

I have a datatype that’s more or less a character array. Each space in the array holds a char, which, as per my understanding, is a single byte (8 bits) of information. I need to be able to specify the char value through a binary string… for instance

char someChar = char(0b00110011); 

What I don’t understand is why the max value I can specify is 0b0XXXXXXX, where I have to leave that MSB set to zero. If I try setting the char like so

char someChar = char(0b11111111);

I get a decimal value: -2147483648, which looks very much like overflow. So I don’t really get what’s going on here. If I call the sizeof() operator on char, I get an answer of 1 (one byte). Doesn’t that mean that I either get 0-255 if the char is unsigned, or -128-127 if the char is signed? Any advice/input would be appreciated.

In response to most of the comments — I converted it to an int before printing it out:
std::cerr << int(someChar)

Thanks to all for the thorough explanations 🙂

  • 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-28T07:44:05+00:00Added an answer on May 28, 2026 at 7:44 am

    -2147483648 in binary is 10000000 00000000 00000000 01111111.

    When you declare you char in binary, you compiler interprets it as a signed char, which is the case for the most compilers. The leftmost bit is interpreted as the sign bit.

    Upon conversion to int, the bit pattern of the value is copied, therefore the seven rightmost bits, and the sign bit is moved to the MSB of the 32-bit block.

    You have two main problems here :

    • First, it seems that you except someChar to be unsigned. If that’s the case, you should tell it to your compiler : unsigned char someChar = unsigned char(0b11111111);
    • Second, the way you put it to the console (which is unknown to us) apparently involves a conversion to int. If it’s not needed, there is likely a way to print someChar for what it is really, i.e. a signed char.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So i have a field that datatype is a text which is feed into
I'm looking for a kind of array data-type that can easily have items added,
I have a column which has a datatype : datetime. But now i want
I have this function which returns a datatype InetAddress[] public InetAddress [] lookupAllHostAddr(String host)
If i takes larger datatype where i know i should have taken datatype that
I have read every where that primitive datatype and object references are passed by
I have a field in tables, with datatype set so that it can accept
We have a client database that is using a float datatype for a column.
I have daily scheduled task that queries a table which includes column named AttemptDate
I have a data type that contains a set and a method that expects

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.