Questions tagged [twos-complement]

Two's complement is a mathematical operation on binary numbers, as well as a binary signed number representation based on this operation.

A two's complement number follows the same principal as a pure binary number, except for the first bit: the most significant bit. If this bit is 0, the binary number is positive, if it's 1 then the number will be negative.

For example:

01110 = 8 + 4 + 2
      = 14

10010 = -16 + 2
      = -14

So 01110 is 14 in denary and 10010 is -14 in denary

683 questions
0
votes
1 answer

finding out bit pattern for 4 bit #

a. Fill in the bit pattern for the following 4-bit numbers. If there are multiple bit patterns for a number, write them all. If no bit pattern exists, write "N/A" in the box. Unsigned, sign/magnitude, one's complement, two's complement for 0,7,-1,…
user1642619
0
votes
2 answers

Flipping a two's complement number's sign using addition, subtraction, and left shifting

On a homework assignment, one of the questions asked us to multiply any arbitrary integer by a constant using only the +, -, and << operators and a maximum of three operations. For example, the first constant was 17, which I solved as (x << 4) +…
bionicOnion
  • 1,494
  • 3
  • 16
  • 25
-1
votes
2 answers

Finding how many bits it takes to represent a 2's complement using only bitwise functions

We can assume an int is 32 bits in 2's compliment The only Legal operators are: ! ~ & ^ | + << >> At this point i am using brute force int a=0x01; x=(x+1)>>1; //(have tried with just x instead of x+1 as well) a = a+(!(!x)); ... with the last 2…
Gadesxion
  • 391
  • 2
  • 6
  • 18
-1
votes
1 answer

How do you determine one's complement and two's complement in Python?

Here's what I have so far: decimalEquivalent is variable that represents an integer. #One's complement of the binary string is shown onesComplement = bin(~decimalEquivalent) print(f'The negative no (-{decimalEquivalent}) using 1\'s Complement:…
Carissa
  • 15
  • 3
-1
votes
1 answer

How to subtract negative numbers from negative numbers using Complement notation?

I've just started learning. I am trying to understand this thoroughly and deeply. I somewhat understand it as long as it's subtraction between a Smaller number from a Larger number or a Larger number from a Smaller number, but when the Minuend in…
-1
votes
1 answer

How does 0FFFFh equal -1?

mov ax, 0ffffh inc ax inc ax Was watching a video on basic Intel X86 Assembly. I thought 0FFFFH was 65535 but in the video they got -1 instead (before the inc instructions run). Just wondering how and why?
localhost
  • 25
  • 3
-1
votes
3 answers

Char addition does not have expected result in C

Can someone explain me how is this at the end a=?,b=?,c=-124 and not a=?,b=?,c=132 This is code: #include int main() { char a = 'D', b='C', c='A'; a = c + 'D'; b = a + b + 'A'; c = b - a; a = a - b + 'C'; b = b - 68; …
-1
votes
1 answer

How to multiply by -1 without using `MUL` or `NEG`

I got an assignment to write a program in assembly that can multiply a number by -1 without using the neg or mul instructions. I tried to use shl and shr but I can't make it work for some reason. Does someone know how I can do it? (in the binary…
roee attias
  • 95
  • 1
  • 6
-1
votes
2 answers

Two's Complement Representation of int16_t

I am attempting to display a string representation of an int16_t's Two's Complement. I find the two's complement by (uint16_t)~value + 1; How would I add the 16 bits to a string? char* getBits(const int16_t value) { uint16_t complement =…
-1
votes
1 answer

Value assigned to 0xFFFFFFFF in One's Complement and Two's Complement

This is a short question and I just wanted to clarify something. What is the value assigned to 0xFFFFFFFF in One and Two's Complement? I thought that 0xFFFFFFFF is Two's Complement was -1. However when I used an online Two's Complement calculator, I…
scy17
  • 61
  • 4
-1
votes
1 answer

Convert negative integer to two's complement supporting hex in python

I'm trying to reverse engineer a twos complement GPS code, where the GPS code is a representation of a two's complement number in hex. For example, 0xFEA1C83D is -22951875 in decimal. Using Python, how can I convert -22951875 into 0xFEA1C83D?
Jon Mitten
  • 1,965
  • 4
  • 25
  • 53
-1
votes
1 answer

What if an immediate number is out of range before signed number operations

One of my homework exercises is as follows: mov al,77h sub al,80h AL=_______ CF=_______ OF=_______ When I first saw it, I thought the result of positive number minus positive number won't overflow. And I just made OF equals to 0. But my…
-1
votes
1 answer

can we interpret negative binary as positive too(read the question please)?

I already know the concept of negative binary numbers, The 0 at the position most significant bit represents that the binary is positive and 1 at the position of most significant bit represents that the binary is negative. BUT THE PROBLEM THAT…
user12206273
-1
votes
1 answer

Printing out 16 bit number in Binary LC3

I'm doing some exam practice questions and the first part involves printing out the hexadecimal number (say xFDO1) as a binary number. My code prints the opposite and I know I can reverse this order by making another loop and instead of starting…
bob mcgee
  • 3
  • 2
-1
votes
1 answer

Is there anything wrong if the out come is zero

i'm doing an exercise on two complement, the question sound like this: Solving 11base10 – 11base10 using 2’s complement will lead to a problem; by using 7-bit data representation. Explain what the problem is and suggest steps to overcome the…
X unknown
  • 11
  • 5