in Programming in C
634 views
0 votes
0 votes

What is the output?

in Programming in C
634 views

1 Answer

1 vote
1 vote
as -1 will be represented as 2's complement form

therefore -1 = 1111 1111 in 2's complement (assuming 8 bit representation)

hence -1<<1 will shift above binary bits left by 1

i.e -1<<1 = 1111 1110

therefore result will be "fe" in hexadecimal

or you may also get fffe for 16 bit representation or  ffff fffe for 32 bit representation but hexadecimal value of last 4 least significant bits  will always be 'e' and remaining preceding value will be 'f'

4 Comments

edited by
Negative number can be represented in three ways

1.signed Integer

2.1's complement

3.2's complement

So -1 can be represented as 1000 0001 so 2'scomplement should be 01111111  and left shift we will get 11111110
0
0
@ARJUN SIR ,
yes sir , thank you for your valuable comment
0
0
1
1

Related questions

0 votes
0 votes
1 answer
2
Parshu gate asked in Programming in C Sep 26, 2017
597 views
Parshu gate asked in Programming in C Sep 26, 2017
597 views