Win a copy of Fixing your Scrum this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what would have happened if the byte value had been
01100010
and has to be promoted to int??
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
*** what happens if you are trying to promote char c = 0xffff to int?
00000000 00000000 11111111 11111111?
 
Paul A
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's correct.
------------------
http://pages.about.com/jqplus
Get Certified, Guaranteed!
 
God is a comedian playing for an audience that is afraid to laugh - Voltair. tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic