Take a decimal number from the user. Convert it to different bases (e.g: 2,8,16 etc.) and send those values to the message queue. Write three separate programs to read and display the binary, octal, and hex values from the message queue distinctively.
Sender Program
//This Code is Written by Souvik Ghosh and Debmitra Chatterjee// C Program for Message Queue (Sender Process)#include<stdio.h>#include<sys/ipc.h>#include<sys/msg.h>// structure for message queuetypedefstruct{// message typelong mesg_type;// array to store payLoadint payLoad[100];// data size under payLoadint size;int hex;} message;intmain(){
key_t key;int msgid;// ftok to generate unique key
key =ftok("progfile",65);// msgget creates a message queue// and returns identifier
msgid =msgget(key,0666| IPC_CREAT);//input decimal numberprintf("Write Data: ");int n;scanf("%d",&n);// For Binary
message m1;
m1.mesg_type =2;int temp=n;// decimal to binary convertionint i =0;while(temp >0){
m1.payLoad[i]= temp %2;
temp = temp /2;
i++;}
m1.size=i;// msgsnd to send messagemsgsnd(msgid,&m1,sizeof(m1),0);// display the messageprintf("Send Binary Value: ");for(int j = i -1; j >=0; j--){printf("%d", m1.payLoad[j]);}printf("\n");// For Octal
message m2;
m2.mesg_type=8;
temp=n;// decimal to octal convertion
i =0;while(temp >0){
m2.payLoad[i]= temp %8;
temp = temp /8;
i++;}
m2.size=i;// msgsnd to send messagemsgsnd(msgid,&m2,sizeof(m2),0);// display the messageprintf("Send Octal Value: ");for(int j = i -1; j >=0; j--){printf("%d", m2.payLoad[j]);}printf("\n");// For HexaDecimal
message m3;
m3.mesg_type=16;
m3.hex = n;// msgsnd to send messagemsgsnd(msgid,&m3,sizeof(m3),0);// display the messageprintf("Send HexaDecimal Value: %X",m3.hex);printf("\n");return0;}
Binary Receiver
//This Code is Written by Souvik Ghosh and Debmitra Chatterjee// C Program for Message Queue ( Binary Receiver Process)#include<stdio.h>#include<sys/ipc.h>#include<sys/msg.h>// structure for message queuetypedefstruct{// message typelong mesg_type;// array to store payLoadint payLoad[100];// data size under payLoadint size;} message;intmain(){
key_t key;int msgid;// ftok to generate unique key
key =ftok("progfile",65);// msgget creates a message queue// and returns identifier
msgid =msgget(key,0666| IPC_CREAT);
message m1;printf("Receiving message.....\n");// msgrcv to receive messagemsgrcv(msgid,&m1,sizeof(m1),2,0);// display the messageprintf("Received Binary Value: ");int i=m1.size;for(int j = i -1; j >=0; j--){printf("%d", m1.payLoad[j]);}printf("\n");// to destroy the message queuemsgctl(msgid, IPC_RMID,NULL);return0;}
Octal Receiver
//This Code is Written by Souvik Ghosh// C Program for Message Queue (Octal Receiver Process)#include<stdio.h>#include<sys/ipc.h>#include<sys/msg.h>// structure for message queuetypedefstruct{// message typelong mesg_type;// array to store payLoadint payLoad[100];// data size under payLoadint size;} message;intmain(){
key_t key;int msgid;// ftok to generate unique key
key =ftok("progfile",65);// msgget creates a message queue// and returns identifier
msgid =msgget(key,0666| IPC_CREAT);
message m2;printf("Receiving message.....\n");// msgrcv to receive messagemsgrcv(msgid,&m2,sizeof(m2),8,0);// display the messageprintf("Received Octal Value: ");int i=m2.size;for(int j = i -1; j >=0; j--){printf("%d", m2.payLoad[j]);}printf("\n");// to destroy the message queuemsgctl(msgid, IPC_RMID,NULL);return0;}
Hex Receiver
//This code is Written by Souvik Ghosh// C Program for Message Queue (Hex Receiver Process)#include<stdio.h>#include<sys/ipc.h>#include<sys/msg.h>// structure for message queuetypedefstruct{// message typelong mesg_type;// array to store payLoadint payLoad[100];// data size under payLoadint size;int hex;} message;intmain(){
key_t key;int msgid;// ftok to generate unique key
key =ftok("progfile",65);// msgget creates a message queue// and returns identifier
msgid =msgget(key,0666| IPC_CREAT);
message m3;printf("Receiving message.....\n");// msgrcv to receive messagemsgrcv(msgid,&m3,sizeof(m3),16,0);// display the messageprintf("Received HexaDecimal Value: %X",m3.hex);printf("\n");// to destroy the message queuemsgctl(msgid, IPC_RMID,NULL);return0;}
Unlock Success in Your MAKAUT Semester Exam with These Empowering Artificial Intelligence Suggestions! Elevate Your Learning Experience and Excel with Confidence.
Unlock Success in Your MAKAUT Semester Exam with These Empowering Mixed Signal Design Suggestions! Elevate Your Learning Experience and Excel with Confidence.
Unlock Success in Your MAKAUT Semester Exam with These Empowering Fiber Optic Communication Suggestions! Elevate Your Learning Experience and Excel with Confidence.
Unlock Success in Your MAKAUT Semester Exam with These Empowering Cyber Security Suggestions! Elevate Your Learning Experience and Excel with Confidence.
Transform your web design game with my CSS cheatsheet! Master the art of styling, dive into essential properties and selectors, and create visually stunning websites effortlessly. Whether…