Hi,
Could someone please explain what sign-extension means? If I have a hex
number 0x55, how does this get sign-extended? Can a sign-extended
counterpart be equal to -91? In a program I'm expecting 0x55 in return
from a function whereas I am getting -91 every time.. does this mean
anything? Thanks
Sona 10 17834
"Sona" <so**********@n ospam.com> wrote in message
news:3f******** @clarion.carno. net.au... Hi,
Could someone please explain what sign-extension means? If I have a hex number 0x55, how does this get sign-extended?
Try asking this question in comp.programmin g.
Can a sign-extended counterpart be equal to -91? In a program I'm expecting 0x55 in return from a function whereas I am getting -91 every time.. does this mean anything?
It means you are doing something wrong. Hard to tell without more
context. Gi'us some code. The bit pattern 0x55 is not negative in any
C integral type I can think of. Try reproducing the problem with as little
code as possible and post it here.
--
Thomas.
Sona wrote: Hi,
Could someone please explain what sign-extension means?
Sign extension is usually a low-level (i.e. assembly) processor term.
In most applications using the C language, there is no concern about
sign extension as that is accounted for in the definition of the
language.
Basically, sign extension is extending the sign of a number (positive
or negative) from a single unit integer to a multi-unit integer.
For example, if you have an integer representing 0x55 and wish to
use two integers (to extend the range), you would set up the second
integer to be zero, which is the sign for a positive number (not
true for all platforms). Negativity is a bit different.
Let us assume for example, that in a given system, -1 is represented
by all bits set to one. When using two integers, the combination
must represent -1. So, the second integer is set to all ones to
extend the sign of the first integer.
Search for these programming concepts:
Multiple Precision Arithmetic
One's Compliment
Two's Compliment
If I have a hex number 0x55, how does this get sign-extended?
See above.
Can a sign-extended counterpart be equal to -91?
I believe you are confusing sign-extension with signed representation
of a number.
In Twos Compliment notation, I am get 0xA5 as -91 (8-bit unit).
Sign extending to 16-bits results in 0xFFA5, to 32 bits: 0xFFFFFFA5.
In a program I'm expecting 0x55 in return from a function whereas I am getting -91 every time.. does this mean anything? Thanks
Sona
I have no idea. There may be an infinite number of relationships
between -91 and 0x55; Two's Complement negativity isn't one of them.
Have you tried single stepping through the function with a debugger?
Or even using printf statements within the function?
--
Thomas Matthews
C++ newsgroup welcome message: http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq: http://www.raos.demon.uk/acllc-c++/faq.html
Other sites: http://www.josuttis.com -- C++ STL Library book
"Sona" <so**********@n ospam.com> wrote in message
news:3f******** @clarion.carno. net.au... Hi,
Could someone please explain what sign-extension means? If I have a hex number 0x55, how does this get sign-extended?
Try asking this question in comp.programmin g.
Can a sign-extended counterpart be equal to -91? In a program I'm expecting 0x55 in return from a function whereas I am getting -91 every time.. does this mean anything?
It means you are doing something wrong. Hard to tell without more
context. Gi'us some code. The bit pattern 0x55 is not negative in any
C integral type I can think of. Try reproducing the problem with as little
code as possible and post it here.
--
Thomas.
Sona wrote: Hi,
Could someone please explain what sign-extension means?
Sign extension is usually a low-level (i.e. assembly) processor term.
In most applications using the C language, there is no concern about
sign extension as that is accounted for in the definition of the
language.
Basically, sign extension is extending the sign of a number (positive
or negative) from a single unit integer to a multi-unit integer.
For example, if you have an integer representing 0x55 and wish to
use two integers (to extend the range), you would set up the second
integer to be zero, which is the sign for a positive number (not
true for all platforms). Negativity is a bit different.
Let us assume for example, that in a given system, -1 is represented
by all bits set to one. When using two integers, the combination
must represent -1. So, the second integer is set to all ones to
extend the sign of the first integer.
Search for these programming concepts:
Multiple Precision Arithmetic
One's Compliment
Two's Compliment
If I have a hex number 0x55, how does this get sign-extended?
See above.
Can a sign-extended counterpart be equal to -91?
I believe you are confusing sign-extension with signed representation
of a number.
In Twos Compliment notation, I am get 0xA5 as -91 (8-bit unit).
Sign extending to 16-bits results in 0xFFA5, to 32 bits: 0xFFFFFFA5.
In a program I'm expecting 0x55 in return from a function whereas I am getting -91 every time.. does this mean anything? Thanks
Sona
I have no idea. There may be an infinite number of relationships
between -91 and 0x55; Two's Complement negativity isn't one of them.
Have you tried single stepping through the function with a debugger?
Or even using printf statements within the function?
--
Thomas Matthews
C++ newsgroup welcome message: http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq: http://www.raos.demon.uk/acllc-c++/faq.html
Other sites: http://www.josuttis.com -- C++ STL Library book
"Sona" <so**********@n ospam.com> wrote in message
news:3f******** @clarion.carno. net.au... Hi,
Could someone please explain what sign-extension means? If I have a hex number 0x55, how does this get sign-extended? Can a sign-extended counterpart be equal to -91? In a program I'm expecting 0x55 in return from a function whereas I am getting -91 every time.. does this mean anything? Thanks
You can't get -91 from 0x55 in C.
In a C implementation where char are signed, and twos complement, -91 would
be 0xA5 in 8 bits, or 0xFFFFFFA5 in 32 bits. C requires a minimum of 8
bits for a char.
-- glen
In article <Hwpcb.573738$u u5.94114@sccrns c04> "Glen Herrmannsfeldt" <ga*@ugcs.calte ch.edu> writes: "Sona" <so**********@n ospam.com> wrote in message news:3f******** @clarion.carno. net.au... Could someone please explain what sign-extension means? If I have a hex number 0x55, how does this get sign-extended? Can a sign-extended counterpart be equal to -91? In a program I'm expecting 0x55 in return from a function whereas I am getting -91 every time.. does this mean anything? Thanks
You can't get -91 from 0x55 in C.
In a C implementation where char are signed, and twos complement, -91 would be 0xA5 in 8 bits, or 0xFFFFFFA5 in 32 bits. C requires a minimum of 8 bits for a char.
struct foo {
signed char foo: 7;
} foo;
int main(void) {
foo.foo = 0x55;
printf("%d\n", foo.foo);
}
But this will print -43, not -91 ;-).
But (signed char)(0x55 + 0x550) will do the trick if a char is 8 bits.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
"Dik T. Winter" <Di********@cwi .nl> writes: In article <Hwpcb.573738$u u5.94114@sccrns c04> "Glen Herrmannsfeldt" <ga*@ugcs.calte ch.edu> writes: > "Sona" <so**********@n ospam.com> wrote in message > news:3f******** @clarion.carno. net.au... > > Could someone please explain what sign-extension means? If I have a hex > > number 0x55, how does this get sign-extended? Can a sign-extended > > counterpart be equal to -91? In a program I'm expecting 0x55 in return > > from a function whereas I am getting -91 every time.. does this mean > > anything? Thanks > > You can't get -91 from 0x55 in C. > > In a C implementation where char are signed, and twos complement, -91 would > be 0xA5 in 8 bits, or 0xFFFFFFA5 in 32 bits. C requires a minimum of 8 > bits for a char.
struct foo { signed char foo: 7; } foo;
int main(void) { foo.foo = 0x55; printf("%d\n", foo.foo); }
But this will print -43, not -91 ;-). But (signed char)(0x55 + 0x550) will do the trick if a char is 8 bits.
....on your implementation. Signed char in a bitfield is a
constraint violation (§6.7.2.1#4). Other than that, converting
0x55 (which is a positive number) to an integer type which cannot
represent it will either yield an implementation-defined value
(could be anything), or will raise an implementation-defined
signal.
-Micah
"Micah Cowan" <mi***@cowan.na me> wrote in message
news:m3******** ****@localhost. localdomain... "Dik T. Winter" <Di********@cwi .nl> writes: In article <Hwpcb.573738$u u5.94114@sccrns c04> "Glen Herrmannsfeldt"
<ga*@ugcs.calte ch.edu> writes: > "Sona" <so**********@n ospam.com> wrote in message > news:3f******** @clarion.carno. net.au... > > Could someone please explain what sign-extension means? If I have a
hex > > number 0x55, how does this get sign-extended? Can a sign-extended > > counterpart be equal to -91? In a program I'm expecting 0x55 in
return > > from a function whereas I am getting -91 every time.. does this
mean > > anything? Thanks > > You can't get -91 from 0x55 in C. > > In a C implementation where char are signed, and twos complement, -91
would > be 0xA5 in 8 bits, or 0xFFFFFFA5 in 32 bits. C requires a minimum
of 8 > bits for a char.
struct foo { signed char foo: 7; } foo;
int main(void) { foo.foo = 0x55; printf("%d\n", foo.foo); }
But this will print -43, not -91 ;-). But (signed char)(0x55 + 0x550) will do the trick if a char is 8 bits.
...on your implementation. Signed char in a bitfield is a constraint violation (§6.7.2.1#4).
It presumably doesn't voilate the constraint on that implementation.
"A bit-field shall have a type that is a qualified or unqualified version
of
_Bool, signed int, unsigned int, or some other implementation-defined
type."
I don't know if this constraint exists for C90. [I don't think so, BICBW]
--
Peter
On Wed, 24 Sep 2003 17:08:12 GMT, Thomas Matthews
<Th************ **********@sbcg lobal.net> wrote:
<snip> Search for these programming concepts: Multiple Precision Arithmetic One's Compliment Two's Compliment
The correct spelling of this word is "complement "; searching for that
is more likely to find correct answers. There is also an argument that
the apostrophe should be moved in "ones' complement" (and more
generally in radix-minus-one complement) but that is not nearly as
good an indicator.
Also note that pretty much all machines/CPUs today are 2sC. It is
useful to understand the concepts of 1sC, and also the simpler ones
for Sign-and-Magnitude, and how some features of the C standard
allow(ed) for them, but don't expect to encounter them in practice.
- David.Thompson1 at worldnet.att.ne t This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: John Dunlop |
last post by:
Q: What does @ (at-sign) do?
A: @ is an operator, which, when prepended to an expression,
suppresses error messages.
Example:
http://www.php.net/manual/en/language.operators.errorcontrol.php
|
by: cooldv |
last post by:
i know how to replace the sign " when SUBMITTING a form in asp by this
code:
message = Replace(usermessage, "'", "''").
My problem is DISPLAYING data in an asp FORM, from an an access
database, when the data already contains a " sign
problem is like this:
access database .... to update on the internet .... a *dataupdate.asp*
page ........
|
by: tarmat |
last post by:
sorry for this silly little question, but whats the function to grab
the sign of a value?
|
by: Claude Gagnon |
last post by:
Hi,
How can we compare sign of numbers in C++ ?
Bye,
Claude
|
by: Jimmy |
last post by:
I'm trying to find a website that does the following:
1. Signs you up to a second site under a different primary domain (i.e.
as a result of a checkout or something). The username and password may
be automatically generated.
2. Signs on for you and redirects you to the second site without the
need of you signing up or signing in
I can't...
| |
by: Steve K. |
last post by:
I recall a few months ago coming across an article allowing for encoding
(or converting?) xml and html documents into sign language as well as
brail for deaf and blind people, and that they were pending an ISO
designations.
I cannot seem to find any information on this. From what I recall they
were supposed to be use able in <metacharset or...
|
by: =?ISO-8859-1?Q?Konrad_M=FChler?= |
last post by:
Hi,
a simple question:
Which standard function in c++ gives me the sign of a number?
Thanks
Konrad
|
by: George2 |
last post by:
Hello everyone,
I am surprised to see that the value of sign ' is the same as \'. So,
there is no need to add sign \ before sign '? In my past knowledge of
sign ', we always need to add sign \ before sign '. Any comments?
Here is my simple program to test.
|
by: Nick |
last post by:
I've seen a few frameworks use the following:
function $(id) { return document.getElementById(id); }
Then to use:
$('something').innerHTML = 'blah';
I'm just trying to roll this out to my site and so far doing this has
saved about 8KB of javascript (lots of ajax/dynamic elements). I just
|
by: Ravikiran |
last post by:
Hi Friends,
I wanted know about whatt is ment by zero optimization and
sign optimization and its differences....
Thank you...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |