Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- int number = 0;
- // %d is a base 10 number (Decimal)
- // %c is a character
- // %x is a base 16 number (heXadecimal)
- // -1 is the same as 255 as a character End Of File
- // 0 \0 null-terminator
- // 7 \a alarm
- // 8 \b backspace
- // 9 \t tab
- // 10 \n new line (line feed)
- // 13 \r carriage return
- while(number < 256)
- {
- printf("%d: 0x%x (%c)\n", number, number, number);
- number++;
- }
- // 8 bit binary
- // 0 0 0 0 0 1 0 1 5
- // ___ ___ ___ ___ ___ ___ ___ ___
- // 128 64 32 16 8 4 2 1
- // << left shift
- // >> right shift
- printf("%d\n", 1 << 0); // 1 <-- 2^0
- printf("%d\n", 1 << 1); // 2 <-- 2^1
- printf("%d\n", 1 << 2); // 4 <-- 2^2
- printf("%d\n", 1 << 3); // 8 <-- 2^3
- printf("%d\n", 3 << 1); // 6
- printf("%d\n", 5 << 2); // 20
- printf("%d\n", 5 >> 1); // 2 (1 bit falls off of the register)
- printf("%d\n", 1 << 30); // ~1billion <-- 2^30
- printf("%d\n", 1 << 31); // ~-2billion <-- 2^31 <-- the sign bit
- // most significant place reserved for negatives
- printf("%d\n", 1 << 32); // 0 <-- moved all the way off of the register
- printf("%d\n", 1 << 33); // 0
- return 0; // signals the main function to stop.
- }
Add Comment
Please, Sign In to add comment