/* * programming_binary_hex.c * * Created on: Sep 22, 2024 * Author: johnsontimoj */ ///////////////////////////////////// // // A few examples of programming binary values // // inputs: user // outputs: prints // ///////////////////////////////////// #include #include int main(void){ setbuf(stdout, NULL); // splash printf("--------------------------------\n"); printf("-- practice with ints and floats\n"); printf("--------------------------------\n\n"); int8_t intval8; uint8_t uintval8; float float_val; float float_valb; int hex_val; intval8 = 127; uintval8 = 255; float_valb = 2.5; float_val = 2.3; // signed wrapping printf("8 bit signed int: %i\n", intval8); intval8++; printf("8 bit signed int: %i\n", intval8); --intval8; printf("8 bit signed int: %i\n", intval8); // unsigned_wrapping printf("8 bit signed int: %i\n", uintval8); uintval8++; printf("8 bit signed int: %i\n", uintval8); --uintval8; printf("8 bit signed int: %i\n", uintval8); // float resolution limitations // while(1){ // printf("Please enter a float value: "); // scanf("%f", &float_val); // printf("float_val is %f\n", float_val); // printf("float_val is %.10f\n", float_val); // // }// end while // more float resolution limitations printf("example: 1,000,000 * (2.5 - (2.2 + 0.3)) = %.10f\n", 1000000 * (2.5 - (2.2 + 0.3))); printf("example: 1,000,000 * (2.5 - (2.2 + 0.3)) = %.10f\n", 1000000 * (float_valb - (float_val + 0.2))); // print in hex while(1){ printf("enter a value in hex: "); scanf("%x", &hex_val); printf("This is hex: %x\n", hex_val); } // end while return 0; }// end main