signed/unsigned byte

L

Lamefif

how can the computer tell the difference between the two?
i mean a byte is 8 bit can be 1 or 0

11111111 = 255 unsigned byte

10000000 = -128 or 128 ?
 
B

Bo Persson

Lamefif wrote:
:: how can the computer tell the difference between the two?
:: i mean a byte is 8 bit can be 1 or 0
::
:: 11111111 = 255 unsigned byte
::
:: 10000000 = -128 or 128 ?

It isn't the byte itself that is different, it is the instructions
used to manipulate it.


Bo Persson
 
S

Scott McPhillips [MVP]

Lamefif said:
how can the computer tell the difference between the two?
i mean a byte is 8 bit can be 1 or 0

11111111 = 255 unsigned byte

10000000 = -128 or 128 ?

Different programming is used for signed and unsigned. The assembly
language of the processor typically provides two kinds of branch
instructions. For unsigned data a branch opcode checks the carry flag
(which is kind of like a 9th bit after an arithmetic operation). For signed
checks another branch opcode checks the sign bit, which is the 8th bit of
the byte. That is why C++ has both signed and unsigned types: It affects the
code that is generated to test arithmetic results.
 
V

Victor Bazarov

Lamefif said:
how can the computer tell the difference between the two?

An object of 'signed char' type is signed. An object of
'unsigned char' type is unsigned. An object of type 'char'
is signed or unsigned depending on the implementation.
i mean a byte is 8 bit can be 1 or 0

11111111 = 255 unsigned byte

It's -1 on two's complement, if treated as signed.
10000000 = -128 or 128 ?

It depends on how you look at it.

0x34562ef9 - a long or a float?

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,049
Members
47,652
Latest member
Campbellamy

Latest Threads

Top