What is the advantage of uint8_t over unsigned char?
It documents your intent – you will be storing small numbers, rather than a character. Also it looks nicer if you’re using other typedefs such as uint16_t or int32_t.
It documents your intent – you will be storing small numbers, rather than a character. Also it looks nicer if you’re using other typedefs such as uint16_t or int32_t.
For example, package main import ( “encoding/binary” “fmt” “math” ) func Float64frombytes(bytes []byte) float64 { bits := binary.LittleEndian.Uint64(bytes) float := math.Float64frombits(bits) return float } func Float64bytes(float float64) []byte { bits := math.Float64bits(float) bytes := make([]byte, 8) binary.LittleEndian.PutUint64(bytes, bits) return bytes } func main() { bytes := Float64bytes(math.Pi) fmt.Println(bytes) float := Float64frombytes(bytes) fmt.Println(float) } Output: [24 … Read more
Ok, let’s get truly pedantic. After reading this, this and this, I’m pretty confident that I understand the intention behind both Standards. So, doing reinterpret_cast from std::uint8_t* to char* and then dereferencing the resulting pointer is safe and portable and is explicitly permitted by [basic.lval]. However, doing reinterpret_cast from char* to std::uint8_t* and then dereferencing … Read more
If it exists, uint8_t must always have the same width as unsigned char. However, it need not be the same type; it may be a distinct extended integer type. It also need not have the same representation as unsigned char; for instance, the bits could be interpreted in the opposite order. This is a silly … Read more
It doesn’t really print a blank, but most probably the ASCII character with value 5, which is non-printable (or invisible). There’s a number of invisible ASCII character codes, most of them below value 32, which is the blank actually. You have to convert aa to unsigned int to output the numeric value, since ostream& operator<<(ostream&, … Read more