This site works best with JavaScript enabled
Sign In
Discussions
Activity
Sign In
All
Query
Share your queries
Query
PROGRAM TO PRINT 1BYTE FROM 4 BYTES OF INT
anubala331
August 2014
/*..PROGRAM TO PRINT 1BYTE FROM 4 BYTES OF INT..*/
#include<stdio.h>
int main()
{
int i=45678,j=0;/
/this is 32 bit system //so int is of 32 bits../
/
j=i;/
/PRESERVE VALUE IN J...BCZ IIN I ..WE ARE SHIFTING VALUE
i=i<<24;
//TO PRINT 1ST BYTE...FROM 32BITS ...MAKE 24 LEFT SHIFT & THEN 24 RIGHT SHIFT TO REMOVE ALL GARBAGE VALUES FROM THAT INT TYPE ..//
i=i>>24;
printf("1st byte of i=%d\n",i);
i=j;
i=i<<16;
//TO PRINT 2ND BYTE OF INT ...16 LEFT SHIFT & THEN 24 RIGHT ..MAKE 2ND BYTE AS LAST 8 BITS..BY REMOVING ALL GARBAGE..//
i=i>>24;
printf("2nd byte of i=%d\n",i);
i=j;
i=i<<8;//
TO PRINT 3RD BYTE OF INT ..BY MAKING 8 LEFT SHIFT & 24 RIGHT SHIFT..
i=i>>24;/
/SO BY MAKING ALL 3RD BYTE AS RIGHTMOST 8 BITS OF INT INTEGER BY REMOVING ALL GARBAGE
printf("3rd byte of i=%d\n",i);
i=j;
i=i>>24;/
/I SAME WAY,..4TH BYTE OF INT WHICH IS LEFTMOST 8 BITS OF 4 BYTE INT ...IN RIGHT SHIFTED 24...BY REMOVING ALL GARAGE..THIS WILL BE PRINTED
printf("4th byte of i=%d\n",i);
return 0;
}
anubala331
August 2014
OUTPUT:
[root@localhost]/home/c-asignments/ass# ./a.out
1st byte of i=110
2nd byte of i=-78
3rd byte of i=0
4th byte of i=0
[root@localhost]/home/c-asignments/ass#
Add a Comment
Powered by
Vanilla
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
0
Module.101: Advanced Data Structures using C
16
Module.303: Linux System Programming
32
Project 22. Ethernet Network Device Driver Development
0
Project.14. Linux System and Network Administration
0
Project.10. Embedded Linux ARM, Configuring and Porting using Storage
0
Project.203 Linux System Programming. MySQL
0
Pravjot Sir Classes
108
Events at EmbLogic
2
Query
503
Module.000: Linux System Administration
21
Project.001: C Programming, Data Structures
74
Project.002: OOPs, C++, Eclipse, Linux
17
Project.003: Linux System Programming
31
Project.004: Linux Network Programming
7
Project.005: Character Device Drivers Development
16
Project.105: Parallel Port Device Drivers Development
5
Project.205: Serial Port Device Drivers Development
3
Project.008: Block Device Driver Development
3
Project.009: Embedded Linux-ARM. Storage
6
Module.011: Shell Scripting using Bash
6
Project 12: Linux Kernel Architecture and Internals
2
Project.015: Python with Eclipse on Linux
2
Project 16: SPI Device Driver Development
2
Project 17: I2C Device Driver Development
0
Project 18: PCI Device Driver Development
0
Project 19: Embedded Linux on ARM Using Network TFTP
0
Project 20: CAN Bus Protocol and Driver Development
0
Project 21: USB Device Drivers Development
0
Embedded Linux
0
ARM Embedded Processor
0
Training
2
Members Area
1
Word From Admin
1