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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:28:10+00:00 2026-05-23T06:28:10+00:00

I have the following signed integers: (4bits)a = 6; (4bits)b = 7; (4bits)c; c

  • 0

I have the following signed integers:

(4bits)a = 6;
(4bits)b = 7;
(4bits)c;
c = a + b;

Will c = 13 or c= -3?
If I do binary math and assume it’s a 4 bit number:
0110+0111=1101 (-8 + 4 + 0 + 1) = -3

  • 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-23T06:28:11+00:00Added an answer on May 23, 2026 at 6:28 am

    Contrary to popular belief, C does have 4-bit integer types. However, it doesn’t have objects of those types, only bit-fields (6.7.2.1/9, “A bit-field is interpreted as a signed or unsigned integer type consisting of the specified number of bits”):

    #include <stdio.h>
    
    typedef struct int4bit {
        signed int value:4;
    } int4bit;
    
    int main() {
        int4bit a, b, c;
        a.value = 6;
        b.value = 7;
        c.value = a.value + b.value;
        printf("%d\n", c.value);
    }
    

    The output of this program with my compiler is -3, however this is not guaranteed by the standard. The reason is that the expression a.value + b.value has type int (because of integer promotion rules, 6.3.1.1/2), and value 13. The value 13 cannot be represented in a 4 bit signed integer, and therefore one of two things happens: either an implementation-defined result or an implementation-defined signal (6.3.1.3/3).

    In short, all you can do is check your compiler documentation, or run the code and see what it does. But this result, -3, is pretty natural for an implementation with 2s complement representation of signed integer types.

    The value can’t be 13, because 13 is not in the range of values representable by a 4 bit signed integer. Anything is permitted as long as the implementation documents it, for example it could naturally be -2, on a 1s’ complement machine with no overflow checking. Not that you’ll likely ever encounter such a machine…

    That’s something of a special case because the only way to get a 4 bit integer type is as a bit-field. In general, overflow of signed integer arithmetic is undefined behavior (6.5/5, “result is … not in the range of representable values for its type”). There’s no arithmetic overflow in your example because of the promotion to int, so the range of behavior available to the implementation is limited – it’s not allowed to format your hard drive. But if you do overflow an int then you’re totally at the mercy of your compiler.

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

Sidebar

Related Questions

In my navbar I have the following: Signed in as <%= link_to current_user.name, edit_password_path(current_user)
I have the following code snippet in vhdl: signal s: signed(31 downto 0); s
I have the following test block in rspec: describe for signed-in users do let(:user)
I have following plist: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>
I have following source. In insertMessage(..), it calls selectMessage to check whether duplicate record
I have following div in a page (I can not modify). <div id=:0.control>Click me</div>
I have following fiddle: http://jsfiddle.net/BFSH4/ As you see there are two issues: The h1
I have following script that executes all the .reg files in the current directory.
I have following nested objects. I am using @Valid for validation in my controller.
I have following code in initialization im = imread('Image02.tif'); figure(); imagesc(im); colormap(gray); [hImage hfig

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.