LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-20-2015, 11:31 PM   #1
atlantis43
Member
 
Registered: Feb 2013
Posts: 289

Rep: Reputation: Disabled
Bit "overflow" for negative numbers


This may be a trivial question, but I'm wondering if there is any way of expressing an overflow bit for a negative value while performing Bit manipulations in C Programming (if there would ever be such a need)?
Is there any equivalent of (1)00001011 for a negative?
Thanks
 
Old 03-20-2015, 11:35 PM   #2
mdooligan
Member
 
Registered: Feb 2009
Location: Vancouver BC
Distribution: Mandrake10/ArchHackery/Gentoo
Posts: 179

Rep: Reputation: 22
That's the high bit. Bit 8. 1000 0001 is -1 (signed char).

Last edited by mdooligan; 03-20-2015 at 11:37 PM.
 
1 members found this post helpful.
Old 03-21-2015, 12:35 AM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,864
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
What bit manipulation do you mean? Shift (<< >>)?
 
1 members found this post helpful.
Old 03-21-2015, 10:12 AM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082
Quote:
Originally Posted by atlantis43
I'm wondering if there is any way of expressing an overflow bit for a negative value
I don't understand what you mean by "expressing an overflow bit".

Quote:
Originally Posted by mdooligan View Post
1000 0001 is -1 (signed char).
Not if the machine uses 2's complement, which is the case for pretty much all computers in use today.

If I recall correctly the C standard doesn't specify which encoding to use for signed numbers.
 
1 members found this post helpful.
Old 03-21-2015, 10:20 AM   #5
atlantis43
Member
 
Registered: Feb 2013
Posts: 289

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by NevemTeve View Post
What bit manipulation do you mean? Shift (<< >>)?
I guess I'm referring more to simple problems like bit-wise addition % subtraction, but I think that I've "seen the light" that my question is not relevant.
Thanks anyhow.
 
Old 03-22-2015, 11:03 AM   #6
mdooligan
Member
 
Registered: Feb 2009
Location: Vancouver BC
Distribution: Mandrake10/ArchHackery/Gentoo
Posts: 179

Rep: Reputation: 22
Quote:
Originally Posted by ntubski View Post
Not if the machine uses 2's complement, which is the case for pretty much all computers in use today.
Oops. My bad. That was a quickie post before I signed off for the night. I must have been sleepy
Code:
1111 1111 = -1, 
1000 0001 = -127, 
1000 0000 = -128.
^
High bit.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
what is "sticky bit mode" , "SUID" , "SGID" augustus123 Linux - General 10 08-03-2012 04:40 AM
VirtualBox 3.1.0 Desktop Goes "Negative" On Exit tronayne Linux - Virtualization and Cloud 5 12-23-2009 09:52 AM
Shouldn't "Slackware64" Become just "Slackware" and 32-bit Become "Slackware32"? foodown Slackware 6 06-23-2009 01:24 PM
"neighbour table overflow" error msg on linux 9 kumardineshwar Linux - Software 2 01-17-2007 07:35 PM
LXer: Title: Linux Kernel "get_fdb_entries()" Integer Overflow ... LXer Syndicated Linux News 0 11-30-2006 03:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration