Skip to content

Instantly share code, notes, and snippets.

@JuniorPolegato
Created August 22, 2014 20:33
Show Gist options
  • Save JuniorPolegato/48e4a8938b7db3afb10b to your computer and use it in GitHub Desktop.
Save JuniorPolegato/48e4a8938b7db3afb10b to your computer and use it in GitHub Desktop.
# include <stdio.h>
int main(int argc, char* argv[]){
char a = 1 << 7;
unsigned char b = 2 * (a - 1) + 1;
short int c = 1 << 15;
unsigned short int d = 2 * (c - 1) + 1;
long int e = 1L << 31;
unsigned long int f = 2 * (e - 1) + 1;
long long int g = 1LL << 63;
unsigned long long int h = 2 * (g - 1) + 1;;
printf("char: %u bits => de %d a %d\n", sizeof(a) * 8, a, ~a);
printf("unsigned char: %u bits => de 0 a %u\n", sizeof(b) * 8, b);
printf("short: %u bits => de %d a %d\n", sizeof(c) * 8, c, ~c);
printf("unsigned short: %u bits => de 0 a %u\n", sizeof(d) * 8, d);
printf("long: %u bits => de %ld a %ld\n", sizeof(e) * 8, e, ~e);
printf("unsigned long: %u bits => de 0 a %lu\n", sizeof(f) * 8, f);
printf("long long: %u bits => de %lld a %lld\n", sizeof(g) * 8, g, ~g);
printf("unsigned long long: %u bits => de 0 a %llu\n", sizeof(h) * 8, h);
printf("\nNeste sistema int tem %u bits!\n", sizeof(int) * 8);
return 0;
}
/*
char: 8 bits => de -128 a 127
unsigned char: 8 bits => de 0 a 255
short: 16 bits => de -32768 a 32767
unsigned short: 16 bits => de 0 a 65535
long: 32 bits => de -2147483648 a 2147483647
unsigned long: 32 bits => de 0 a 4294967295
long long: 64 bits => de -9223372036854775808 a 9223372036854775807
unsigned long long: 64 bits => de 0 a 18446744073709551615
Neste sistema int tem 32 bits!
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment