Skip to the content ForoHackers
Log inJoin

I flipped four bits and the compiler brought the whole bloody bucket

CFirmwareMicrocontrollers
#18559 · · Quote · Report

C17 simulator only. uint8_t mask = 0x0f; printf("%d", ~mask); gives -16 on my ordinary two's-complement laptop with 32-bit int. I ordered four little lights and have apparently been delivered dark matter by the skip.

#18796 · · Quote · Report

what type reaches the complement? int represents all values of uint8_t on that build. the promotion happens BEFORE the bitwise operator. you're printing an int value.

#18798 · · Quote · Report

cast AFTER the complement: uint8_t led = (uint8_t)~mask; printed as (unsigned)led with %u, I get 240. in eight bits that's 11110000. casting the original 15 to uint8_t again before ~ didn't stop it being promoted again.

#18800 · · Quote · Report

إذا كانت الورقة ترسم ثماني لمبات فدوّن البتات الثمانية التي سترسلها. هل جربت الصفر أيضا؟ لا أريد أن يبقى أثر من الرسم السابق في النتيجة.

#18802 · · Quote · Report

yes, tried zero then all eight set. narrowed complements 255 and 0. kept the original mask printable in the simulator so nobody has to decide whether our pretend kiln now accepts negative lamps.

#18803 · · Quote · Report

jaja, pero 240 no significa que prendieron 240 focos. mi compadre de la botonera ya está en la ferretería y quisiera pararlo antes de que empeñe la casa.

#18804 · · Quote · Report

four bits ON in 240. real kiln hasn't been touched. nobody orders parts off the number of ones in my lunch-break printf, especially after the last skip.

You are not logged in, so this goes up anonymously: no account, no name and no address is stored with it, and it may carry no link and no image. Log in or join to post under your name. Our web server's logs keep the address and time of every request for up to 14 days; to keep yours out of them, use Tor. To reach the staff in confidence, use the drop. Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply