C Programming Code Examples C > Bitwise Operators Code Examples C Program to Print the Range of Fundamental Data Types C Program to Print the Range of Fundamental Data Types - Convert the number of bytes into bits by multiplying the bytes with 8. - Use two functions namely signed_one() and unsigned_one() for calculating the range of signed and unsigned data types respectively. - Value got at step 1 is sent as a parameter to both the functions. In both the function, it is received by variable count. - Initialize the variable pro to 1 in both the functions. - In the function signed_one() using while loop with the condition (count != 1), shift the variable pro to its left by 1 position and decrement the variable count by 1 consecutively. - When the loop terminates, assign the complement of pro to the variable min and increment the min by 1. Decrement the variable pro and assign it to the variable max. Print min and max as output. - In the function unsigned_one() using while loop with the condition (count !=0), shift the variable pro to its left by 1 position and decrement the variable count by 1 consecutively. - When the loop terminates, assign zero to the variable min. Decrement the variable pro and assign it to the variable max. Print min and max as output. #include <stdio.h> #define SIZE(x) sizeof(x)*8 void signed_one(int); void unsigned_one(int); void main() { printf("\nrange of int"); signed_one(SIZE(int)); printf("\nrange of unsigned int"); unsigned_one(SIZE(unsigned int)); printf("\nrange of char"); signed_one(SIZE(char)); printf("\nrange of unsigned char"); unsigned_one(SIZE(unsigned char)); printf("\nrange of short"); signed_one(SIZE(short)); printf("\nrange of unsigned short"); unsigned_one(SIZE(unsigned short)); } /* returns the range signed*/ void signed_one(int count) { int min, max, pro; pro = 1; while (count != 1) { pro = pro << 1; count--; } min = ~pro; min = min + 1; max = pro - 1; printf("\n%d to %d", min, max); } /* returns the range unsigned */ void unsigned_one(int count) { unsigned int min, max, pro = 1; while (count != 0) { pro = pro << 1; count--; } min = 0; max = pro - 1; printf("\n%u to %u", min, max); }