상세 컨텐츠

본문 제목

2의 보수 구하기

Python 기초학습

by 달의 언어 2023. 4. 11. 09:17

본문


To easily explain how to find the 2's complement of a binary number, follow these two steps:

Invert the bits: Change all 0s to 1s and all 1s to 0s in the given binary number. This is also known as finding the 1's complement.

Add 1: Add 1 to the result obtained from step 1, and if there's a carry bit after the last position, ignore it.

Let's illustrate with an example:

Given binary number: 1101 (which is 13 in decimal)

Step 1: Invert the bits
Original: 1101
Inverted: 0010

Step 2: Add 1
Inverted: 0010
+ 1
Result: 0011

So, the 2's complement of 1101 is 0011 (which is -3 in decimal, considering 1101 as a 4-bit signed binary number).

관련글 더보기

댓글 영역