OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

pkcs11 message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


Subject: RE: [pkcs11] Ones Complement versus Twos Complement - RE: Use CK_UNAVAILABLE_INFORMATION


I was going to say that you need to get out more, but maybe it is longevity that matters.

 1. The original IBM scientific machines, 701, 704, 7090, etc., were signed-magnitude machines.

 2. It was commonplace for machines that employed decimal (actually, binary-coded-decimal) arithmetic in some form to use signed-magnitude.  The IBM 650, 703, 7070, 1401, 1410, and of course all of the packed-decimal arithmetics in the IBM System 360 lineage used signed-magnitude arithmetic.  Univac I and II used signed-magnitude also.  The binary arithmetic subset in Univac III might have been signed-magnitude as well.

 3. The Univac 1103A, 418, 490, 1107, 1108, 1110 and their cousins/descendants at CDC and UniSys were 1's complement machines as I recall.  The Burroughs 5000 descendants had rather different word sizes (48 bits?) and I don't know about the use of signs or complements.  Those architectures were still running in the wild the last time I checked.  That was a while ago.

I don't know about DEC machines before the PDP-11 architecture, nor do I recall what the numerical model was for Multics, various GE/Honeywell machines, and the IBM Stretch and related supercomputers.  (The Univac LARC was a decimal machine.)

The ubiquity of 8-bit architectures and the System 360 data models, along with the extensive presence of C Language has certainly led to more homogeneity, along with commodity processor chips and memory structures.

If you want to go all-out on portability, you need to consider that unsigned is the most likely common case but that not all longs are created equal.  There are also systems where the void-addressible and char storage unit are not 8 bits, too, so you might prefer to use <limits.h> rather than sizeof in some cases.  For converting between octet streams and internal structures, the Endian Wars are not over, but I don't think that matters so long as ASN.1 BER is handled properly.  It might matter for other things stuffed in a device, but the API might hide some/all of that?

All of this makes ~ suspicious as an operator on values of an integer type if the intention is to have a predictable *numerical* effect.

 - Dennis

PS: I wrote my first line of code 55 years ago this May.  I was 19.  There are older-timers still around and active.

-----Original Message-----
From: pkcs11@lists.oasis-open.org [mailto:pkcs11@lists.oasis-open.org] On Behalf Of Robert Relyea
Sent: Wednesday, June 12, 2013 02:51 PM
To: pkcs11@lists.oasis-open.org
Subject: [pkcs11] Ones Complement versus Twos Complement - RE: Use CK_UNAVAILABLE_INFORMATION

Stef had a question:

Is it ever the case that ~0UL ~= (U_LONG)-1;

The answer is when the processor is not using twos complement arithmetic 
for negative numbers.

In computer architecture text books there are a few ways of handling 
negative numbers.

1) Sign bit: the number has a sign bit, so -1 is <Signbit=1>|| 1 or 
0x80000001 if the word size is 32 bit.
     In this mode, the processor looks at the sign bit of the operands 
and decides which unit (addr or subractor) to send the two operands. 
Multiplication and division strips the sign bits, and calculates the 
sign separately.

2) One's complement: negative numbers are the ones complement of the 
absolute value (-1 = ~1).
    In this mode, the processor only has an addr. If the result 
overflows, the carry bit is added back to the result. Note: in ones 
complement, there are two zeros: 0 and ~0 (or -0).

3) Twos complement: negative numbers are the twos complement of the 
absolute value. Twos complement can be thought of as any of the following:
            -1 = (~1+1)
            -1 = 2^wordsize - 1
    In twos complement, you don't need to do anything special for 
negative numbers, you can just use the same addr and multiplier and 
everything works out OK.


In my 30 years I've seen 1) in real life (out side of text books) in 
only 2 places:  Sign bits on floating point numbers, and sign bits in 
software bit numb libraries. I've seen 2) outside of texts books in one 
place: the exponent field of floating point numbers on the CDC Cyber. 
I've hear rumors that the old Cray computers also used ones complement.

I believe occurrence of ones complement for any fixed point numbers on a 
real processor that actually has a C compilier would be exceedingly rare.

bob




[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]