Questions tagged [ones-complement]

The ones' complement of a numerical value is evaluated by performing a bitwise NOT operation on its binary representation.

The ones' complement of a numerical value is evaluated by performing a NOT operation on its binary representation.

Read also the wikipedia article on Ones' Complement.

91 questions
36
votes
9 answers

Is one's complement a real-world issue, or just a historical one?

Another question asked about determining odd/evenness in C, and the idiomatic (x & 1) approach was correctly flagged as broken for one's complement-based systems, which the C standard allows for. Do systems really exist in the 'real world' outside…
Roddy
  • 66,617
  • 42
  • 165
  • 277
16
votes
1 answer

Detect one's or two's complement architecture in C++?

What is the most reliable way to detect whether the architecture uses one's or two's complement representation in C++?
Vincent
  • 57,703
  • 61
  • 205
  • 388
15
votes
1 answer

Can bitwise operators have undefined behavior?

Bitwise operators (~, &, | and ^) operate on the bitwise representation of their promoted operands. Can such operations cause undefined behavior? For example, the ~ operator is defined this way in the C Standard: 6.5.3.3 Unary arithmetic…
chqrlie
  • 131,814
  • 10
  • 121
  • 189
15
votes
5 answers

How to detect encodings on signed integers in C?

The ISO C standard allows three encoding methods for signed integers: two's complement, one's complement and sign/magnitude. What's an efficient or good way to detect the encoding at runtime (or some other time if there's a better solution)? I want…
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
13
votes
4 answers

1's complement using ~ in C/C++

I am using Visual Studio 2013. Recently I tried the ~ operator for 1's complement: int a = 10; cout << ~a << endl; Output is -11 But for unsigned int a = 10; cout << ~a << endl; the output is 4294967296 I don't get why the output is -11 in the…
user2912611
  • 534
  • 2
  • 6
  • 16
10
votes
2 answers

Why does the negative of Integer.MIN_VALUE give the same value?

Consider the below java code. Integer value = Integer.MIN_VALUE; System.out.println(value); value = -value; System.out.println(value); Output -2147483648 -2147483648 How the negative value of Integer.MIN_VALUE value results the same value?…
Nageswaran
  • 7,481
  • 14
  • 55
  • 74
10
votes
2 answers

From hexadecimal to one's complement in Python

Is there an easy way to produce a one's complement in python? For instance, if you take the hex value 0x9E, I need to convert it to 0x61. I need to swap the binary 1's for 0's and 0's for 1's. It feels like this should be simple.
user1841870
  • 101
  • 1
  • 1
  • 3
9
votes
3 answers

Behaviour of negative zero on a one's complement architecture?

Consider the following code on a one's complement architecture: int zero = 0; int negzero = -0; std::cout<<(negzero < zero)<
Vincent
  • 57,703
  • 61
  • 205
  • 388
7
votes
3 answers

Finding 1's complement

I am trying to make a program to calculate 1's complement after entering a binary number. This is what I have to far: import java.util.Scanner; public class BitWiseComplement { public static void main(String[] args) { Scanner keysIn =…
user2913004
  • 123
  • 1
  • 3
  • 8
6
votes
2 answers

Do Unisys latest mainframe systems still use ones' complement representations?

From the Wikipedia article it seems ones' complement representation for signed integers is mostly obsolete, but they mention some Unisys systems, namely the UNIVAC 1100/2200 series as still supporting this representation. Do the latest systems in…
chqrlie
  • 131,814
  • 10
  • 121
  • 189
6
votes
3 answers

What's the difference between (size_t)-1 and ~0?

I've seen both (size_t)-1 and ~0 used to represent large numbers, or numbers with all their bits flipped. Is there any difference between the two? If so, what is it? I found this question: What is the difference between -1 and ~0, however it did not…
S.S. Anne
  • 15,171
  • 8
  • 38
  • 76
5
votes
3 answers

Why Kotlin considers negative zero less than positive zero

I've just started learning Kotlin and I came across a weird sentence in the documentation of basic types: -0.0 is considered less than 0.0 I understand that their values will not be the same in ones' complement, but I don't know how it might be…
Abdallah Alaraby
  • 2,222
  • 2
  • 18
  • 30
5
votes
1 answer

What is the proper way to construct a BigInteger from an implied unsigned hexadecimal string?

I'm running into a problem where as I have an implied unsigned hexadecimal number as a string, provided from user input, that needs to be converted into a BigInteger. Thanks to the signed nature of a BigInteger any input where the highest order bit…
rheone
  • 1,517
  • 1
  • 17
  • 30
4
votes
1 answer

Just started learning C this semester, but I can't seem to understand what the professor wants from us in this question

Original question: A positive number has the same representation in one’s complement and in two’s complement. Suppose its representation is interpreted as two’s complement, and its additive inverse is determined. Now this representation is …
cinos
  • 117
  • 2
  • 8
4
votes
1 answer

Range of Values Represented by 1's Complement with 7 bits

Assume that there are 7-bits that are available to store a binary number. Specify the range of numbers that can be represented by 1's Complement. I found that the range for 2's Complement is -64 ≤ 0 ≤ 63. How do I do this for 1's Complement?
1
2 3 4 5 6 7