jeudi 1 novembre 2018

std::ofstream weird behavior when writing integers on byte border from 256

Tring to create a binary file format, but weird behaviour.

    std::ofstream outputFile;
    outputFile.open (PATH, std::ios_base::out | std::ios_base::binary |
    std::ios_base::app);
    unsigned long long int timer3 = 255;
    outputFile <<reinterpret_cast<const char *>(&timer3);
    timer3 = 256;
    outputFile <<reinterpret_cast<const char *>(&timer3);
    timer3 = 257;
    outputFile <<reinterpret_cast<const char *>(&timer3);
    timer3 = 258;
    outputFile <<reinterpret_cast<const char *>(&timer3);

Binary output file only contains (in hex) FF 01 01 02 01

FF- 255

01 01- 257

02 01 -258

why does it blatantly disregard 256 (and 512, 1024..)?

Aucun commentaire:

Enregistrer un commentaire