hi, i am suresh. in an interview i was asked to reverse two nibbles in a byte of data.
the question is as follows. suppose a number is assigned to a character like
char c=0x82 then, a function should be described such that it will return number as 0x28
my way of approach is as follows
void main()
{
char c=0x82;
char exch_nibbles(char);
clrscr();
printf("\nThe exchanged value is %x",exch_nibbles(c));
getch();
}
char exch_nibbles(char c)
{
char temp1, temp2;
temp1=c & 0x0F; //to obtain last four bits
temp2=c & 0xF0; //to obtain first four bits
{
char c=0x82;
char exch_nibbles(char);
clrscr();
printf("\nThe exchanged value is %x",exch_nibbles(c));
getch();
}
char exch_nibbles(char c)
{
char temp1, temp2;
temp1=c & 0x0F; //to obtain last four bits
temp2=c & 0xF0; //to obtain first four bits
//printf("\nThe temp1 value is %x",temp1);
//printf("\nThe temp2 value is %x",temp2);
temp1=temp1 << 4; //shifting the last four bits to left
temp2=temp2 >> 4; //shifting the first four bits to right
temp2=temp2 >> 4; //shifting the first four bits to right
printf("\nThe temp1 value after shifting is %x",temp1);
printf("\nThe temp2 value after shifting is %x",temp2);
printf("\nThe temp2 value after shifting is %x",temp2);
return(temp2|temp1); //adding the bits
}
but in the above program, temp1 is taking one byte of memory n value stored in it is 02, but temp2 is taking 2 bytes of memory and storing value as FFF8 before shifting.
}
but in the above program, temp1 is taking one byte of memory n value stored in it is 02, but temp2 is taking 2 bytes of memory and storing value as FFF8 before shifting.
i had tried this program using Turboc3 compiler
pls suggest modification in my program r any other approach to solve this problem
Do you Yahoo!?
Yahoo! Mail - now with 250MB free storage. Learn more.
To unsubscribe : [EMAIL PROTECTED]
| Yahoo! Groups Sponsor | |
|
|
Yahoo! Groups Links
- To reply to this message, go to:
http://groups.yahoo.com/group/Programmers-Town/post?act=reply&messageNum=4952
Please do not reply to this message via email. (more info)
- To visit your group on the web, go to:
http://groups.yahoo.com/group/Programmers-Town/
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
