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

The Archive Base Latest Questions

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

I have a binary value stored in a char in C, I want transform

  • 0

I have a binary value stored in a char in C, I want transform this byte into signed int in C.
Currently I have something like this:

char a = 0xff;
int b = a; 
printf("value of b: %d\n", b);

The result in standard output will be “255”, the desired output is “-1”.

  • 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-09T10:53:15+00:00Added an answer on June 9, 2026 at 10:53 am

    Replace:

    char a = 0xff
    

    by

    signed char a = 0xff;  // or more explicit: = -1
    

    to have printf prints -1.

    If you don’t want to change the type of a, as @veer added in the comments you can simply cast a to (signed char) before assigning its value to b.

    Note that in both cases, this integer conversion is implementation-defined but this is the commonly seen implementation-defined behavior.

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

Sidebar

Related Questions

I have a long hex value stored as a NSString, something like: c12761787e93534f6c443be73be31312cbe343816c062a278f3818cb8363c701 How
I have a binary tree where each node can have a value. I want
Currently have this to get a value from the registry in TSQL. However, I
I have a registry value which is stored as a binary value (REG_BINARY) holding
I have a binary tree of functions and terminal values. I'd like to print
I have a binary image that represents a number in MATLAB: I'd like to
I have multiple binary trees stored as an array. In each slot is either
I have a binary file and documentation of the format the information is stored
I have a binary file which I'm reading where some 2 byte values are
I have a binary file. There are 2288*2288 longitude float values stored in top

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.