Win a copy of Fixing your Scrum this week in the Agile forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Ron McLeod
• Paul Clapham
• Rob Spoor
• Liutauras Vilda
Sheriffs:
• Jeanne Boyarsky
• Junilu Lacar
• Tim Cooke
Saloon Keepers:
• Tim Holloway
• Piet Souris
• Stephan van Hulst
• Tim Moores
• Carey Brown
Bartenders:
• Frits Walraven
• Himai Minh

Promotion

Ranch Hand
Posts: 169
• Number of slices to send:
Optional 'thank-you' note:
if byte b= -1
ie b=11111111
when it is promoted to int what is the rule?
will it become 00000000000000000000000011111111
or
11111111111111111111111111111111
- Thanks

Greenhorn
Posts: 25
• Number of slices to send:
Optional 'thank-you' note:

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
Posts: 169
• Number of slices to send:
Optional 'thank-you' note:
what would have happened if the byte value had been
01100010
and has to be promoted to int??

Ranch Hand
Posts: 44
• Number of slices to send:
Optional 'thank-you' note:
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.)
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.

------------------
Get Certified, Guaranteed!
[This message has been edited by Paul A (edited August 28, 2000).]

Leverager of our synergies
Posts: 10065
• Number of slices to send:
Optional 'thank-you' note:
*** what happens if you are trying to promote char c = 0xffff to int?
00000000 00000000 11111111 11111111?

Paul A
Ranch Hand
Posts: 44
• Number of slices to send:
Optional 'thank-you' note:
That's correct.
------------------