From WikiChip
Editing Sign extender
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
This page supports semantic in-text annotations (e.g. "[[Is specified as::World Heritage Site]]") to build structured and queryable content provided by Semantic MediaWiki. For a comprehensive description on how to use annotations or the #ask parser function, please have a look at the getting started, in-text annotation, or inline queries help pages.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
[[File:Sign extender.svg|right|200px]] | [[File:Sign extender.svg|right|200px]] | ||
[[File:Sign extender square.svg|right|150px]] | [[File:Sign extender square.svg|right|150px]] | ||
− | + | Sign extension is an operation in which the number of bits representing a specific value is increased while preserving the original sign and value. The exact method used to perform this operation depends on underlining signed number representation used on that machine. A '''Sign Extender''' or a '''Sign Extension Unit''' is a black box representation of such operation. The symbols on the right are usually used to represent such unit. | |
== Two's complement sign extension == | == Two's complement sign extension == | ||
− | In today's systems, the most common signed number representation is | + | In today's systems, the most common signed number representation is 2's complement. In two's complement, signed extension is done by simply repeating the most significant bit, the sign bit, into all the new bits we introduce. For example: |
[[File:Sign extender 2s comp.svg|left]] | [[File:Sign extender 2s comp.svg|left]] | ||
Line 29: | Line 29: | ||
{{clear}} | {{clear}} | ||
== Sign-magnitude sign extension == | == Sign-magnitude sign extension == | ||
− | Similar to two's complement, in a | + | Similar to two's complement, in a sign-magnitude representation, the most-significant bit is also used to indicate the sign. Sign extension on sign-magnitude numbers works the same as two's complement. The MSB is repeated across all the new bits that were added. |
== C programming == | == C programming == | ||
In the sample [[C| code]] below. Assuming on this implementation <code>CHAR_BIT = 8</code> and <code>sizeof (int) = 4</code>. The assignment of c to i will | In the sample [[C| code]] below. Assuming on this implementation <code>CHAR_BIT = 8</code> and <code>sizeof (int) = 4</code>. The assignment of c to i will | ||
− | undergo a | + | undergo a sign extension - 24 extra bits will be added. In a two's complement sign representation those 24 bits will be identical to the 8th bit of c. |
<source lang="C"> | <source lang="C"> | ||
char c; | char c; | ||
Line 42: | Line 42: | ||
</source> | </source> | ||
− | [[Category: | + | [[Category:logic gates]] |