#include <stdio.h> int byteBits(int bytes) { return bytes*8; } int bitsByte(int bits) { return bits/8; } int main() { int num, val, result; printf("Press 1 if Byte to Bits\nPress 2 if Bits to Byte\nPress 0 if Cancel\n\n"); printf("Please enter a number [1, 2 or 0]: "); scanf("%d", &num); switch (num) { case 1: printf("Enter the number of bytes: "); scanf("%d", &val); result = byteBits(val); printf("%d bytes = %d bits\n", val, result); break; case 2: printf("Enter the number of bits: "); scanf("%d", &val); result = bitsByte(val); printf("%d bits = %d bytes\n", val, result); break; case 0: printf("Canceled\n"); break; default: printf("Invalid. Please try again.\n"); } return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter