Questions tagged [complement]

This tag is deprecated! Use more specific tags instead: For the binary representations of negative values in computer science, use tags [ones-complement] and [twos-complement]; For the bitwise complement operation, use [bitwise], or [regex-negation] for the use of complement patterns in regular expressions, or [bit-manipulation] for complementing said data.

This tag is deprecated! Please consider use of the following tags instead:

112 questions
1
vote
2 answers

Python3 Byte Level Bit Operations

Is there a byte type in Python3? I only know there is a bytearray. What I want is that, there is a byte 0x01, then do the Complement Operator ~ the result will be 0xFE, however when I do the following steps, the result is -2 and -2 can't be added to…
xuanzhui
  • 1,300
  • 4
  • 12
  • 30
1
vote
1 answer

Adding two Negative Numbers using 2's Complement

I was wondering if someone could double check my work for me real quick. If I'm given two negative numbers: -33 and -31. If I add them together what will be the result using 2's complement. NOTE: A word length of 6-bits MUST being used for the…
jaredjones
  • 137
  • 1
  • 2
  • 6
1
vote
2 answers

Negate Unsigned Number in Bash

I have a number (hex) and I want the one's complement of it. For example if X = 20 I want bash to perform a negation and return Y = ~X = DF. It doesn't have to be in bash, but it should use a common command line tool that I can wrap into a script.…
mjschultz
  • 1,936
  • 1
  • 18
  • 20
1
vote
2 answers

2s Complement of a negative zero

I have problem: you know the 2s Complement so you can get the negative number of a positive one with the reverse and adding a one. e.g. 8 Bit 121 = 0111 1001 1st= 1000 0110 + 0000 0001 --------- 1000 0111 --> -121 So now if we…
ThePom
  • 95
  • 3
  • 13
1
vote
0 answers

Efficient implementation of bfs algorithm for a subgraph of a complete graph

I'm stuck in the following problem: I have the adjacency lists of a subgraph which is part of a complete graph. What I want to do is to apply bfs algorithm to the complement of the given subgraph. So, to do that, I need the succesors of each vertex…
svecax
  • 369
  • 1
  • 3
  • 13
1
vote
1 answer

how to take 1s complement in C++ in the following code?

I want to take a 1s complement of whatever bits are there in sum+ and save the complemented bits in finalsum. how to do that. I am a bit weak with using bitvec and uint32_t type stuff. so i am confused here. please help. #include…
user899714
  • 455
  • 6
  • 13
  • 23
1
vote
1 answer

How to prove this theory I found out? Quicker way of doing 2's complement(finding out the value of a negative binary)

I was playing around with 2's complement and found a quicker way of finding the value of a negative binary. Please help me prove this(right or wrong) or why it works! Thanks in advance! 2's complement is very useful for finding the value of a…
Simon Yundov
  • 63
  • 1
  • 9
1
vote
3 answers

Complement of empty index vector is empty index vector again

I know this question was already posted but the answer was a trick to solve the given problem some other way, but the core question remained unanswered. The question is this. somevector <- 1:5 emptyindeces <- vector() somevector[-emptyindeces]…
1
vote
1 answer

Does the sign-bit change when using one's or two's complement?

I've been struggling with what seems like simple concepts, but I seem to keep combining and mixing up binary conversions. If you are given a number in binary and apply 1's complement, you invert all bits. Making the 0's 1's and 1's 0's. For 2's…
ModdedLife
  • 669
  • 2
  • 11
  • 24
1
vote
1 answer

Elements in a set that are not elements of another set (relative complement)

In matlab, how can I implement the following? Say that I have some set A and another set B, both of which have some elements. How can I write a function that returns only the values of B that are not in A (relative complement of A in B B\A? Thanks.
Simplicity
  • 47,404
  • 98
  • 256
  • 385
1
vote
3 answers

Understanding signed numbers and complements in java

I have a 3 byte signed number that I need to determine the value of in Java. I believe it is signed with one's complement but I'm not 100% sure (I haven't studied this stuff in more than 10 years and the documentation of my problem isn't super…
rjcarr
  • 2,072
  • 2
  • 22
  • 35
1
vote
3 answers

how to calculate the one's complement for positive and negative number?

If I use one's complement to represent number, what result should I get? For example, number 01110 ( a positive number),its one's complement should be 01110 or 10001? if the number is 10001 ( a negative number), the one's complement value is 01110? …
Dean Chen
  • 3,800
  • 8
  • 45
  • 70
0
votes
1 answer

Signed magnitude, 1's complement and 2's complement of +46 and -17

can anyone verify if am I correct? +46 (7 bits) S.M : 0101110 1's C. : 0101110 ( the same ) 2's C. : 0101110 ( the same ) -17 (7 bits) S.M : 1010001 1's C. : 1101110 2's C. : 1101111
EnexoOnoma
  • 8,454
  • 18
  • 94
  • 179
0
votes
0 answers

How to convert hexadecimal 2's complement to decimal in python

I am new to programming and python. I am struggling to find a consistent way to convert hexadecimal 2's complement to decimal. For example, find the decimal of 0xc001 and 0x7fff. I have tried (H is the input): finding the inverse (0xffff -…
0
votes
3 answers

How to collect the intersection and both complements of two arrays within one task?

Arrays - const source = [1, 1, 1, 3, 4]; const target = [1, 2, 4, 5, 6]; Empty arrays - const matches1 = []; const matches2 = []; const unmatches1 = []; Loop - for (const line of source) { const line2Match = target.find((line2) => { const…