Redirected
recategorized by
3,029 views

4 Answers

8 votes
8 votes

Answer : D

They are asking to print ("%x",-1>>4); this

Lets take this A/C to Answer given write the 1 in 16 bits

0000 0000 0000 0001

-1 can be written in 2's complement no system as

1111 1111 1111 1111

">>" This Operator is called Binary Right Shift Operator ,So we have to right shift the o/p bits and fill the shifted bits with 0

0000 1111 1111 1111

   0       F      F       F

edited by
5 votes
5 votes

-1 (2'scomplement)

0000 0000 0000 0001 (1)

1111 1111 1111 1111(2's complement) -----   -1

>>4 right shifts 4 bits

0000 1111 1111 1111  

=0FFF which is option B

Option B

4 votes
4 votes

According to The C Programming language by Dennis M. Ritchie , Page 49 Second Paragraph

Right Shifting a signed quantity will fill with sign bits on some machines and with "0-bits" on others.

Suppose int occupies 2 Bytes then -1 will be represented as 11111111 11111111 in 2's complement form

Right Shifting it by 4 bits and fill with sign bits 11111111 11111111 = ffff  // %x  prints answer in hexadecimal form

Right Shifting it by 4 bits and fill with 0 bits 00001111 11111111 = offf

Both A and B are correct. It depends on machines.

2 votes
2 votes
a>>b if b is negative then result is unpredictable

        if a is negative then result depends on whether sign extension is performed or not by the machine on which a program is executed.

-1 will be stored in memory as its 2's complement as 1111 1111 1111 1111

on machine on which sign extension is performed -1>>4 will output 1111 1111 1111 1111 i.e. ffff

on machine on which sign extension is not performed -1>>4 will output 0000 1111 1111 1111 i.e. 0fff

On most of the compiler like turbo c,Codeblocks etc sign extension is done so (a) will be the answer.

Related questions

1 votes
1 votes
1 answer
1
go_editor asked Mar 28, 2020
468 views
The following determiniotic finite automata recognizes:Set of all strings containing $’ab’$Set of all strings containing $’aab’$Set of all strings ending in $’a...
0 votes
0 votes
0 answers
2
go_editor asked Mar 28, 2020
687 views
Depth ion travels of the following directed graph is:$\text{A B C D E F}$$\text{A B D E F C}$$\text{A C E B D F}$None of the above
0 votes
0 votes
0 answers
3
go_editor asked Mar 28, 2020
1,119 views
The maximum number of nodes in a binary tree of depth $10$:$1024$ $2^{10}-1$ $1000$None of the above
1 votes
1 votes
1 answer
4
go_editor asked Mar 28, 2020
1,225 views
The regular expression given below describes:$r=(1+01)$*$(0+\lambda)$Set of all string not containing $’11’$Set of all string not containing $’00’$Set of all stri...