Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualCornstalks

Posted 07 February 2013 - 08:57 PM

It depends on your platform's negative number representation. Most modern machine will use 2's complement which will go from -128 to 127, but neither C nor C++ guarantee it. The C standard's SCHAR_MIN is listed as -127 not -128.



If you include the standard header , C++ defines alot of integer types that are more specific:
int8_t = -127 to +127

Actually int8_t is =-128 to 127


As has been mentioned, on two's complement architectures, yes. 1's complement architectures do exist (although more "did"), having the advantage of slightly simpler circuitry. For practical purposes, nowadays, on commodity hardware, one generally assumes two's complement.


No, int8_t is 2's complement with no padding bits.
 
Servant of the Lord explicitly mentioned (and was corrected by BornToCode) using the u/intN_t types. The C standard states (which the C++ standard references in section 18.4.1 and requires to be compliant with the C standard):
 

7.20.1.1 Exact-width integer types
1 The typedef name intN_t designates a signed integer type with width N, no padding
bits, and a two’s complement representation. Thus, int8_t denotes such a signed
integer type with a width of exactly 8 bits.
2 The typedef name uintN_t designates an unsigned integer type with width N and no
padding bits. Thus, uint24_t denotes such an unsigned integer type with a width of
exactly 24 bits.
3 These types are optional. However, if an implementation provides integer types with
widths of 8, 16, 32, or 64 bits, no padding bits, and (for the signed types) that have a
two’s complement representation, it shall define the corresponding typedef names.

 
That is, these data types are required to be the specified number of bits in 2's complement representation. Section 7.20.2.1 confirms the ranges:
 

7.20.2.1 Limits of exact-width integer types
1 — minimum values of exact-width signed integer types
INTN_MIN exactly −(2N−1)
— maximum values of exact-width signed integer types
INTN_MAX exactly 2N−1− 1
— maximum values of exact-width unsigned integer types
UINTN_MAX exactly 2N− 1

 
You are, of course, correct in that non-exact width integer types (like char, short, int, etc.) may not be 2's complement (and of course, the macros giving the min and max values for each type take this into account like you note with SCHAR_MIN/MAX).

#3Cornstalks

Posted 07 February 2013 - 08:56 PM

It depends on your platform's negative number representation. Most modern machine will use 2's complement which will go from -128 to 127, but neither C nor C++ guarantee it. The C standard's SCHAR_MIN is listed as -127 not -128.



If you include the standard header , C++ defines alot of integer types that are more specific:
int8_t = -127 to +127

Actually int8_t is =-128 to 127


As has been mentioned, on two's complement architectures, yes. 1's complement architectures do exist (although more "did"), having the advantage of slightly simpler circuitry. For practical purposes, nowadays, on commodity hardware, one generally assumes two's complement.


No, int8_t is 2's complement with no padding bits.
 
Servant of the Lord explicitly mentioned (and was corrected by BornToCode) using the u/intN_t types. The C standard states (which the C++ standard references in section 18.4.1 and requires to be compliant with the C standard):
 

7.20.1.1 Exact-width integer types
1 The typedef name intN_t designates a signed integer type with width N, no padding
bits, and a two’s complement representation. Thus, int8_t denotes such a signed
integer type with a width of exactly 8 bits.
2 The typedef name uintN_t designates an unsigned integer type with width N and no
padding bits. Thus, uint24_t denotes such an unsigned integer type with a width of
exactly 24 bits.
3 These types are optional. However, if an implementation provides integer types with
widths of 8, 16, 32, or 64 bits, no padding bits, and (for the signed types) that have a
two’s complement representation, it shall define the corresponding typedef names.

 
That is, these data types are required to be the specified number of bits in 2's complement representation. Section 7.20.2.1 confirms the ranges:
 

7.20.2.1 Limits of exact-width integer types
1 — minimum values of exact-width signed integer types
INTN_MIN exactly −(2N−1)
— maximum values of exact-width signed integer types
INTN_MAX exactly 2N−1− 1
— maximum values of exact-width unsigned integer types
UINTN_MAX exactly 2N− 1

 
You are, of course, correct in that non-exact width integer types (like char, int, etc.) may not be 2's complement (and of course, the macros giving the min and max values for each type take this into account like you note with SCHAR_MIN/MAX).

#2Cornstalks

Posted 07 February 2013 - 08:45 PM

It depends on your platform's negative number representation. Most modern machine will use 2's complement which will go from -128 to 127, but neither C nor C++ guarantee it. The C standard's SCHAR_MIN is listed as -127 not -128.
[/quote]



If you include the standard header , C++ defines alot of integer types that are more specific:
int8_t = -127 to +127
[/quote]
Actually int8_t is =-128 to 127
 
[/quote]
As has been mentioned, on two's complement architectures, yes. 1's complement architectures do exist (although more "did"), having the advantage of slightly simpler circuitry. For practical purposes, nowadays, on commodity hardware, one generally assumes two's complement.[/quote]
No, int8_t is 2's complement with no padding bits.
 
Servant of the Lord explicitly mentioned (and was corrected by BornToCode) using the u/intN_t types. The C standard states (which the C++ standard references in section 18.4.1 and requires to be compliant with the C standard):
 

7.20.1.1 Exact-width integer types
1 The typedef name intN_t designates a signed integer type with width N, no padding
bits, and a two’s complement representation. Thus, int8_t denotes such a signed
integer type with a width of exactly 8 bits.
2 The typedef name uintN_t designates an unsigned integer type with width N and no
padding bits. Thus, uint24_t denotes such an unsigned integer type with a width of
exactly 24 bits.
3 These types are optional. However, if an implementation provides integer types with
widths of 8, 16, 32, or 64 bits, no padding bits, and (for the signed types) that have a
two’s complement representation, it shall define the corresponding typedef names.

 
That is, these data types are required to be the specified number of bits in 2's complement representation. Section 7.20.2.1 confirms the ranges:
 

7.20.2.1 Limits of exact-width integer types
1 — minimum values of exact-width signed integer types
INTN_MIN exactly −(2N−1)
— maximum values of exact-width signed integer types
INTN_MAX exactly 2N−1− 1
— maximum values of exact-width unsigned integer types
UINTN_MAX exactly 2N− 1


 
You are, of course, correct in that non-exact width integer types (like char, int, etc.) may not be 2's complement (and of course, the macros giving the min and max values for each type take this into account like you note with SCHAR_MIN/MAX).
[/quote]





#1Cornstalks

Posted 07 February 2013 - 08:44 PM

It depends on your platform's negative number representation. Most modern machine will use 2's complement which will go from -128 to 127, but neither C nor C++ guarantee it. The C standard's SCHAR_MIN is listed as -127 not -128.

 

If you include the standard header , C++ defines alot of integer types that are more specific:
int8_t = -127 to +127

Actually int8_t is =-128 to 127

 

As has been mentioned, on two's complement architectures, yes. 1's complement architectures do exist (although more "did"), having the advantage of slightly simpler circuitry. For practical purposes, nowadays, on commodity hardware, one generally assumes two's complement.

No, int8_t is 2's complement with no padding bits.

 

Servant of the Lord explicitly mentioned (and was corrected by BornToCode) using the u/intN_t types. The C standard states (which the C++ standard references in section 18.4.1 and requires to be compliant with the C standard):

 

 

7.20.1.1 Exact-width integer types
1 The typedef name intN_t designates a signed integer type with width N, no padding
bits, and a two’s complement representation. Thus, int8_t denotes such a signed
integer type with a width of exactly 8 bits.
2 The typedef name uintN_t designates an unsigned integer type with width N and no
padding bits. Thus, uint24_t denotes such an unsigned integer type with a width of
exactly 24 bits.
3 These types are optional. However, if an implementation provides integer types with
widths of 8, 16, 32, or 64 bits, no padding bits, and (for the signed types) that have a
two’s complement representation, it shall define the corresponding typedef names.
 
That is, these data types are required to be the specified number of bits in 2's complement representation. Section 7.20.2.1 confirms the ranges:
 

7.20.2.1 Limits of exact-width integer types
1 — minimum values of exact-width signed integer types
INTN_MIN exactly −(2N−1)
— maximum values of exact-width signed integer types
INTN_MAX exactly 2N−1− 1
— maximum values of exact-width unsigned integer types
UINTN_MAX exactly 2N− 1

 

You are, of course, correct in that non-exact width integer types (like char, int, etc.) may not be 2's complement (and of course, the macros giving the min and max values for each type take this into account like you note with SCHAR_MIN/MAX).


PARTNERS