naseeam
asked on
Can function argument type char be typecasted to unsigned int?
Please consider following function definition:
/* write a new value into a dataword */
unsigned int replace_byte (unsigned int dataword, int bytenum,
char byteval)
Can I typecast byteval as follows:
(unsigned int)byteval
If yes, what will be three most significant bytes of byteval after the typecasting. Will they be zeros.
/* write a new value into a dataword */
unsigned int replace_byte (unsigned int dataword, int bytenum,
char byteval)
Can I typecast byteval as follows:
(unsigned int)byteval
If yes, what will be three most significant bytes of byteval after the typecasting. Will they be zeros.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> To avoid that, use an unsigned char :
In that case, the 3 most significant bytes of the unsigned int will ALWAYS be all 0's.
In that case, the 3 most significant bytes of the unsigned int will ALWAYS be all 0's.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
NB. By MSBs I mean Most Significant Bytes :)
unsigned int fun(unsigned char byteval) {
return (unsigned int)byteval;
}