Function that converts bits to bytes, bytes to bits. Call each function inside a switch case statement. Note: 1 byte = 8 bits.

PHOTO EMBED

Thu Apr 25 2024 09:31:56 GMT+0000 (Coordinated Universal Time)

Saved by @kervinandy123 #c

#include <stdio.h>

int byte2bits(int x);
int bits2byte(int x);

int main() {
    int choice, answer, byte, bit; 
    
    printf("[1] Byte to Bits [8] Bits to Byte [0] Exit\n");
    printf("Enter Choice:");
    scanf("%d", &choice);
    
    switch(choice)
{
    case 1:printf("Enter the number of byte:");
            scanf("%d", &byte);
            answer=byte2bits(byte);
            printf("%d byte/s = %d bit/s", byte, answer);
            
    break;
    case 8:printf("Enter the number of bits:");
            scanf("%d", &bit);
            answer=bits2byte(bit);
            printf("%d bit/s = %d byte/s", bit, answer);
            
    break;
    case 0:printf("\n\nExited Succesfully!");
    break;
}
}
int byte2bits(int x)
{
return(x*8);
}
int bits2byte(int x)
{
return(x/8);
}
content_copyCOPY