Posts

Showing posts with the label binary

How exactly does binary code work? - José Américo N L F de Freitas

Video Channel: TED-Ed Check out our Patreon page: http://www.patreon.com/teded View full lesson: http://ed.ted.com/lessons/how-exactl... Imagine trying to use words to describe every scene in a film, every note in a song, or every street in your town. Now imagine trying to do it using only the numbers 1 and 0. Every time you use the Internet to watch a movie, listen to music, or check directions, that’s exactly what your device is doing, using the language of binary code. José Américo N L F de Freitas explains how binary works. Lesson by José Américo N L F de Freitas, animation by Qa'ed Mai. Thank you so much to our patrons for your support! Without you this video would not be possible! Bev Millar, Rishi Pasham, Jhuval, SookKwan Loong, Daniel Day, Nick Johnson, Bruno Pinho, Javier Aldavaz, Rodrigo Carballo, Marc Veale, Boytsov Ilya, maxi kobi einy, Misaki Sato, Craig Sheldon, Andrew Bosco, Catherine Sverko, Nik Maier, Mark Morris, Tamás Drávai, Adi V, Peter Liu, Leora Allen, Hiros...

C++ How to convert a vector of size 4 into a 32 bit float

C++ How to convert a vector<uint8_t> of size 4 into a 32 bit float What is the fastest way to convert a vector of size 4 into a 32 bit float? My failed attempt: static bool vec2float32(std::vector<uint8_t> bytes, float &result) { if(bytes.size() != 4) return false; uint8_t sign = (bytes.at(0) & 0x10000000); //will be 1 or 0 uint8_t exponent = (bytes.at(0) & 0x01111111); uint16_t mantissa = (bytes.at(1) << (2*8)) + (bytes.at(2) << (1*8)) + (bytes.at(3) << (0*8)); result = (2^(exponent - 127)) * mantissa; if(sign == 1) result = result * -1; return true; } memcpy, all major compilers handle it optimally. Btw, you have bugs in the 0xXXX constants. You used binary, but 0x means hexadecimal. – geza Jun 29 at 9:42 ^ is bitwise...