Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an actual 8-bit integer data type in C++

Tags:

c++

integer

In c++, specifically the cstdint header file, there are types for 8-bit integers which turn out to be of the char data type with a typedef. Could anyone suggest an actual 8-bit integer type?

like image 704
tej-kweku Avatar asked Feb 06 '16 20:02

tej-kweku


People also ask

Is 8-bit int in C?

The minimum size for char is 8 bits, the minimum size for short and int is 16 bits, for long it is 32 bits and long long must contain at least 64 bits. The type int should be the integer type that the target processor is most efficiently working with.

What is integer data type in C?

Software Engineering C data type Integer is defined as a number which has no fractional component. Numbers which have a fractional component is known floating point numbers.


Video Answer


1 Answers

Yes, you are right. int8_t and uint8_t are typedef to char on platforms where 1 byte is 8 bits. On platforms where it is not, appropriate definition will be given.

Following answer is based on assumption that char is 8 bits

char holds 1 byte, which may be signed or unsigned based on implementation.

So int8_t is signed char and uint8_t is unsigned char, but this will be safe to use int8_t/uint8_t as actual 8-bit integer without relying too much on the implementation.

For a implementer's point of view, typedeffing where char is 8 bits makes sense.

Having seen all this, It is safe to use int8_t or uint8_t as real 8 bit integer.

like image 84
dlmeetei Avatar answered Sep 22 '22 20:09

dlmeetei