This week's book giveaways are in the Java EE and JavaScript forums. We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line! See this thread and this one for details.

//Here is the o/p..... output is 0xf1 I am not understading ..how the o/p is 0xf1 ...pls...explain this.BTW..wht. is masking sign extention ?? THANKS IN ADVANCE. <marquee>RATUL </marquee>

hi ratul In hex[(b>>4)&0x0f], b is changed to int before shift, which means all 24bits to the left of initial is filled with 1s, then the shift takes place, now the right extreme 4 bits will be filled with 1s, which is ANDed by 0f, which will result in f, now hex[f] is equal to f from array. Next b is taken again it is ANDed with 0f straightaway without any shifting operation, this result only one at the right most position and all the remaining bits zero, so now what we have is hex[1], which is equal to 1 as per array. hence the final result is f1. the prefix 0x is added by the string within quotes. i think this will clarify thanks

ratul banji
Ranch Hand

Joined: Mar 15, 2001
Posts: 108

posted

0

HI g,

THANKS g krishnan...but still now ..I am not understanding the concept of "Masking sign extention of shift opt."

Pls..explain this. ratul

ratul banji
Ranch Hand

Joined: Mar 15, 2001
Posts: 108

posted

0

Hi, Pls..can any1 explain me wht. is: "Masking sign extention of shift opt." Thanks. Pls..do ans.

krishnan, can you tell me why the 24 bits left of the original byte are filled with 1's and not 0's? I thought they are filled with 1's only when the sign is negative. When it's positive, it's filled with 0's.

Hi,Cameron It is representing a number in binary base.(base 2). Integer number in java is represented by 32 bits.so when you representing a number say 2 ,it is as follows 0000 0000 0000 0000 0000 0000 0000 0010 = (0 x 1) +(1 x 2) +(0 x 4) ... and so on when U represents a negative number takes the complement of the the (binary code )number (SAY 2) and add 1 (e.g) complement of 2 in 32 bits = 1111 1111 1111 1111 1111 1111 1111 1101 + 0000 0000 0000 0000 0000 0000 0000 0001 ==================================== 1111 1111 1111 1111 1111 1111 1111 1110 = -2 ===================================== back to the Q the MSB ie the most significant bit represents the sign of the number. also the f = 15 in decimal base.binary reperesentation of15 = (binary code) 1111 = (1 x 1) + (1 x 2) +(1 x 4)+(1 x 8) when 0xf1 is converted to int (32 bits) the sign bit remains the same. Actually it is -ve number.Ur thouught is correct. Hope this clear Ur doubt. Regards, vkswami.