if byte b= -1 ie b=11111111 when it is promoted to int what is the rule? will it become 00000000000000000000000011111111 or 11111111111111111111111111111111 - Thanks
robl
Greenhorn
Joined: Aug 26, 2000
Posts: 25
posted
0
Originally posted by Doit: if byte b= -1 ie b=11111111 when it is promoted to int what is the rule? will it become 00000000000000000000000011111111 or 11111111111111111111111111111111 - Thanks
I believe a byte can be promoted to an int automatically (no cast needed) The result will be -1 or 11111111111111111111111111111111 Promotion here should not change the value.
Doit
Ranch Hand
Joined: Aug 03, 2000
Posts: 169
posted
0
what would have happened if the byte value had been 01100010 and has to be promoted to int??
Paul A
Ranch Hand
Joined: Aug 25, 2000
Posts: 44
posted
0
Fact: Whenever you 'promote' something, no information is lost. (Take care while converting int to float and long to double, because float and double by nature are less precise than int and long resp.) Now the answers are easy. if b is -1 ( 11111111 ) then i will also be -1 ( ie 111....) if b is 01100010 then i will be 00000000 00000000 00000000 01100010 Excercise: what happens if you are trying to promote char c = 0xffff to int? ( Note that char is always positive ). HTH, Paul.
------------------ http://pages.about.com/jqplus Get Certified, Guaranteed! [This message has been edited by Paul A (edited August 28, 2000).]