• Post Reply Bookmark Topic Watch Topic
  • New Topic

casting

 
sandhya bhatia
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everybody
pl. help in the conversion part.if some no. is given in byte,how we can convert it into short,long and in others and the vice-versa.
thanks in advance.
sandhya

------------------
 
Vijay Kashyap
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You can easily assign a byte to any other primitve number like short,int.long etc. You donot have to cast it.
int i = byteValue; // no loss of data
long l = byteValue; // no loss of data
but for the other way round you have to explicitly cast from higher order type to lower type and there are chnaces of losing data.
byte b = (byte)intValue; // loss of data
byte b = (byte)longValue; //loss of data
Hope this helps.
Vijay
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!