Bits, Bytes And Data Types Flashcards
Bit
Smallest unit of memory which can hold a value of 0 or 1. (On or off lightswitch)
Memmory addresses
Sequential units where the memory is organized
Byte
Group of bits that are operated on as a unit, comprised of 8 sequential bits, a byte of data is stored in each memory address
Data types
How the compiler interpretes the contents of memory in some meaningful way (ex. Integers)
Fundamental data types
Also called basic, primitive, built-in are data types built in with support of c++
Integers
Specific data types that hold positive and negative whole numbers including 0
Integral types
Includes all boolean, characters and integer types, they are stored in memory as integers
_t suffix
Type, common nomenclature applied to modern types
Void
No type, variables can’t be defined with void type
Use of void
With
- functions that do not return a value
- functions that do not take parameters
For functions that have no paramethers
Use empty paramether list instead of void
Object sizes
Dependant on data types
Single bit
Can hold 2 possible values 0 or 1
Two bits
Can hold 4 possible values
Object with n bits
Can hold 2^n unique valies
Size of an object
Puts a limit on the amount of unique values it can store
Size of a given data type
Dependent on the compiler and/or the computer architecture
Sizeof operator
Unary operator that takes either a type or a variable and returns its size in bytes
Integer
Internal type that can represent positive, negative number and 0
C++ fundamental integer types
Short, int, long and long long
Difference between integer types
They have varying sizes, longer integers can hold big numbers
Numbers sign
Attribute of being positive, negative or zero
Defining signed integers
Short s, int i, long l, long long ll
Range
Set of specific values that a data type can hold
Range of integer variable
Determined by its size and whether is signed or not
Integer overflow
When we try to store value that is out of the range of the type, number we try to store that requres more bits.
Integer division
Doing devision with two integers, produces an integer, the fractions are droped
Unsigned integers
Integers that can only hold none negative whole numbers
Defining unsigned integers
Keyword unsigned is placed before the type
Unsigned integer range
From 0-225 in 1 byte, same as signed but signed use half of those for negative numbers
Integer wrap around
Mistaken for overflow, if value is out of range, its devided by one grater than the largest number of the type, the remainder is kept
Use of unsigned integers
Try to avoid it, if you use it dont mix signed and unsigned numbers
Fixed-width integers
Set of integers in the stdint.h header that are guaranteed to have the same size on any architecture
Defining fixed-width integers
Std::int8_t, std::uint8_t,….std::uint64_t
Accesing fixed-width integers
By including the cstint header, where are defined inside the std namespace
Downsides of fixed-width integers
- optional, only exist if there are fundamental types matching the widths and following certain binary representation
- it may be slower than a wider type on same architectures
- should be avoided
Fast type integers
Std::int_fast#_t provides the fastest signed integer type width of at least # bits.