Integer Types (int, long and long long)

If you are curious about the integer types in the mbed compiler, I have copied a test program IntegerTypes from http://home.att.net/~jackklein/c/inttypes.html and the output is as follows:

Size of Boolean type is 1 byte(s)

Number of bits in a character: 8
Size of character types is 1 byte
Signed char min: -128 max: 127
Unsigned char min: 0 max: 255
Default char is unsigned

Size of short int types is 2 bytes
Signed short min: -32768 max: 32767
Unsigned short min: 0 max: 65535

Size of int types is 4 bytes
Signed int min: -2147483648 max: 2147483647
Unsigned int min: 0 max: 4294967295

Size of long int types is 4 bytes
Signed long min: -2147483648 max: 2147483647
Unsigned long min: 0 max: 4294967295

Size of long long types is 8 bytes
Signed long long min: -9223372036854775808 max: 9223372036854775807
Unsigned long long min: 0 max: 18446744073709551615

Note that int and long are the same size and if you want a 64 bit integer then you need to use long long (or unsigned long long).


6 comments

09 Jan 2010

If you need a specific size and want to make sure, include stdint.h and use [u]int_N_t types.

07 Sep 2010

Thanks for this! I was looking for an int64 equivalent - long long is the way to go.

22 Sep 2011

I have an unsigned long long called Shadow which I need to set specific bits in.

I tried this:

void SetBit(unsigned char b) {
shadow = shadow | (1 << b)
}



It works up to the first 32 bits, but after that my program freezes.

sizeof() shows 8 for shadow variable.

What am I doing wrong?

22 Sep 2011

Never mind, I found out this:

void SetBit(unsigned char b) {
shadow = shadow | (1ull << b)
}

15 Dec 2014 . Edited: 15 Dec 2014
if i have to use 133 bytes then how should i declare?? plz help me out..its very urjent
09 Dec 2017 . Edited: 09 Dec 2017
Hello My name Albert Davis I am working as a thesis writer from Ideal Thesis

You need to log in to post a comment