<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://bsccs.stoney-wiki.com/w/index.php?action=history&amp;feed=atom&amp;title=Signed_Integers_and_Flags_%28Two%E2%80%99s_Complement%29</id>
	<title>Signed Integers and Flags (Two’s Complement) - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://bsccs.stoney-wiki.com/w/index.php?action=history&amp;feed=atom&amp;title=Signed_Integers_and_Flags_%28Two%E2%80%99s_Complement%29"/>
	<link rel="alternate" type="text/html" href="https://bsccs.stoney-wiki.com/w/index.php?title=Signed_Integers_and_Flags_(Two%E2%80%99s_Complement)&amp;action=history"/>
	<updated>2026-05-04T20:17:29Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.6</generator>
	<entry>
		<id>https://bsccs.stoney-wiki.com/w/index.php?title=Signed_Integers_and_Flags_(Two%E2%80%99s_Complement)&amp;diff=103&amp;oldid=prev</id>
		<title>Bfh-sts: Created page with &quot;= Signed Integers and Flags (Two’s Complement) = This page explains how signed integers are represented in x86 architecture using two’s complement and how arithmetic instructions affect CPU flags.  == Unsigned vs signed integers == Unsigned integers represent only positive values.   Signed integers represent both positive and negative values using two’s complement.  Example with 8 bits: * 00000000₂ = 0 * 00000001₂ = +1 * 01111111₂ = +127 * 11111111₂ = −1...&quot;</title>
		<link rel="alternate" type="text/html" href="https://bsccs.stoney-wiki.com/w/index.php?title=Signed_Integers_and_Flags_(Two%E2%80%99s_Complement)&amp;diff=103&amp;oldid=prev"/>
		<updated>2025-10-20T13:47:24Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;= Signed Integers and Flags (Two’s Complement) = This page explains how signed integers are represented in x86 architecture using two’s complement and how arithmetic instructions affect CPU flags.  == Unsigned vs signed integers == Unsigned integers represent only positive values.   Signed integers represent both positive and negative values using two’s complement.  Example with 8 bits: * 00000000₂ = 0 * 00000001₂ = +1 * 01111111₂ = +127 * 11111111₂ = −1...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Signed Integers and Flags (Two’s Complement) =&lt;br /&gt;
This page explains how signed integers are represented in x86 architecture using two’s complement and how arithmetic instructions affect CPU flags.&lt;br /&gt;
&lt;br /&gt;
== Unsigned vs signed integers ==&lt;br /&gt;
Unsigned integers represent only positive values.  &lt;br /&gt;
Signed integers represent both positive and negative values using two’s complement.&lt;br /&gt;
&lt;br /&gt;
Example with 8 bits:&lt;br /&gt;
* 00000000₂ = 0&lt;br /&gt;
* 00000001₂ = +1&lt;br /&gt;
* 01111111₂ = +127&lt;br /&gt;
* 11111111₂ = −1&lt;br /&gt;
* 11111110₂ = −2&lt;br /&gt;
* 10000000₂ = −128&lt;br /&gt;
&lt;br /&gt;
In two’s complement, the most significant bit (MSB) is the sign bit:&lt;br /&gt;
* 0 = positive&lt;br /&gt;
* 1 = negative&lt;br /&gt;
&lt;br /&gt;
== How two’s complement works ==&lt;br /&gt;
To negate a binary number:&lt;br /&gt;
1. Invert all bits.&lt;br /&gt;
2. Add 1 to the result.&lt;br /&gt;
&lt;br /&gt;
Example: Convert +5 (00000101₂) to −5:&lt;br /&gt;
 Invert → 11111010₂  &lt;br /&gt;
 Add 1  → 11111011₂ = −5&lt;br /&gt;
&lt;br /&gt;
== Overflow and wrapping ==&lt;br /&gt;
When signed arithmetic exceeds the representable range, it wraps around and sets the overflow flag (OF).&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
 mov eax, 0x7FFFFFFF   ; largest positive 32-bit signed number&lt;br /&gt;
 inc eax               ; eax becomes 0x80000000 (−2147483648)&lt;br /&gt;
 ; Overflow occurs, OF = 1, SF = 1 (sign bit set)&lt;br /&gt;
&lt;br /&gt;
Decrementing below the smallest value (e.g., −128 for 8-bit) wraps around to the largest positive value.&lt;br /&gt;
&lt;br /&gt;
== Example: continuous decrement ==&lt;br /&gt;
 mov eax, 0&lt;br /&gt;
loop2:&lt;br /&gt;
 dec eax&lt;br /&gt;
 jmp loop2&lt;br /&gt;
&lt;br /&gt;
EAX changes as follows:&lt;br /&gt;
 0x00000000 → 0xFFFFFFFF (−1)&lt;br /&gt;
 → 0xFFFFFFFE (−2)&lt;br /&gt;
 → 0xFFFFFFFD (−3)&lt;br /&gt;
and so on.&lt;br /&gt;
&lt;br /&gt;
== Flags relevant for signed arithmetic ==&lt;br /&gt;
* SF (Sign Flag): set when result is negative (MSB = 1)&lt;br /&gt;
* ZF (Zero Flag): set when result is zero&lt;br /&gt;
* OF (Overflow Flag): set when signed overflow occurs&lt;br /&gt;
* CF (Carry Flag): used for unsigned overflow, not sign interpretation&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
* Two’s complement represents negative numbers naturally.&lt;br /&gt;
* Arithmetic wraps around automatically.&lt;br /&gt;
* Signed overflow is detected via the Overflow Flag (OF).&lt;br /&gt;
* Understanding these flags is essential for conditional branching and comparisons.&lt;br /&gt;
&lt;br /&gt;
[[Category:Assembly Programming]]&lt;/div&gt;</summary>
		<author><name>Bfh-sts</name></author>
	</entry>
</feed>