Serial << (buffer) << F("]") << endl // Data to Serial Monitor Sprintf(buffer, "%08lu", (uint32_t)(val)) // Formatting zeros Sprintf(buffer, "%02u", MLSBval) // Formatting zeros Sprintf(buffer, "%010lu", MLSBval) // Formatting zeros Since it seems to be the only complete solution to solve this kind of problem that I was able to find on the web then, if anyone finds any bugs or like to improve it, feel free to reply to (or edit) this post. If desired, it can be generalized to be used with all types of integers (depends on your Arduino board microcontroller type).įor now is tested only with uint64_t on Arduino Uno R3 (ATmega328P). This solution is not very elegant, but at least works well for my purpose. For higher numbers the formula should not work correctly, but for some reason (I'm still trying to figure out why) when I send the result on the Serial it returns the right number even with the highest number (255 255 255 255 255 255 255 255 ).Ĭheck the accepted answer for more solutions that do not relies on Streaming.h library. Serial << F("") << endl Īs you can see I have not yet found the right solution. How do I print a 64 bit number in decimal given 32 bit integer I'm using streaming.h for serial communication. So, is there an algorithm that given a number as input, the returned result are two numbers that are the breakdown of the previous binary number in MSBs and LSBs? So when I send it in sequence on the Serial I see a 142, but instead what I would is 226. Thus I try to split the number in two parts with a bitwise mask: 1110 <- MSBs (14 in Decimal) Then send each number in sequence on the Serial port, but obviously the resulting number is different from the original 64-bit number.įor example, I use an unsigned 8-bit number as follows: 11100010 <- 226 in DecimalĪnd I need to send it to my serial port, but it can only handle 4-bit numbers at max. To do this I was thinking of dividing the number in two blocks of 32 bit each with a bitwise operation. Thus, I need to print that (64-bit) number as Decimal on Serial port only. How can I overcome these limitations and print all possible 64 bit unsigned integers as decimal numbers?įor an Arduino project I need to send a number on Serial that fits on a uint64_t variable type, but for some reason the Arduino Serial port can't handle a type bigger than 32 bit (but the device supports a 6-bit type). The compiler provided for Arduino seems to generate code that can work with 64 bit numbers, but the I/O classes, for instance Serial.Print(), seem to not work beyond 32 bit numbers.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |