+ 1

How to get ones compliment of a binary number using bitwise operator

Please help me

22nd Nov 2021, 4:04 AM
VENKATA SATHWIK REDDY DANDA
10 odpowiedzi
+ 2
To get the one's complement apply the unary bitwise not operator, ~.
22nd Nov 2021, 5:59 AM
Brian
Brian - avatar
+ 2
VENKATA SATHWIK REDDY DANDA suppose you wish to replace the value in k with its one's complement. It is a simple assignment: k = ~k; Now all of the bits in k are flipped opposite of what they were. Every 1 becomes 0, and every 0 becomes 1. That is one's complement.
22nd Nov 2021, 6:45 AM
Brian
Brian - avatar
+ 1
Thank you very much
22nd Nov 2021, 6:48 AM
VENKATA SATHWIK REDDY DANDA
+ 1
VENKATA SATHWIK REDDY DANDA your results are correct for a signed data type. Try using an unsigned data type. Also if you are using printf then change the format specifier to unsigned, like "%ud".
22nd Nov 2021, 7:03 AM
Brian
Brian - avatar
0
Will u pls write me the code
22nd Nov 2021, 6:18 AM
VENKATA SATHWIK REDDY DANDA
22nd Nov 2021, 6:50 AM
Brian
Brian - avatar
0
Brian I need to convert a number into binary and get ones compliment of obtained binary value pls help
22nd Nov 2021, 6:55 AM
VENKATA SATHWIK REDDY DANDA
0
Brian i tried like that but i am getting like this i gave 1010 i should get 0101 but getting -1011
22nd Nov 2021, 6:56 AM
VENKATA SATHWIK REDDY DANDA
0
Tq
22nd Nov 2021, 7:05 AM
VENKATA SATHWIK REDDY DANDA
0
Tq
22nd Nov 2021, 2:02 PM
VENKATA SATHWIK REDDY DANDA