Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add support for 64 bit integer printing #6608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
RobTillaart wants to merge 1 commit into arduino:master from RobTillaart:print64
Closed

Add support for 64 bit integer printing #6608

RobTillaart wants to merge 1 commit into arduino:master from RobTillaart:print64

Conversation

Copy link

@RobTillaart RobTillaart commented Aug 13, 2017
edited
Loading

Added support for printing unsigned long long and long long

solves issue #1236

Included is a reference implementation (commented out) which is a replica of the print code for long.
The code is 2-3x faster with a slightly larger footprint. The performance is gained by working in "16 bit" chunks. Tested on UNO and discussed "long long" ago here - http://forum.arduino.cc/index.php?topic=143584

(minor) Cleanup trailing spaces

Ivan-Perez, sadr0b0t, and jendalinda reacted with thumbs up emoji
@facchinm facchinm added the Print and Stream class The Arduino core library's Print and Stream classes label Aug 14, 2017
Copy link
Contributor

Ivan-Perez commented Sep 5, 2017
edited
Loading

Should this be added to the String class, so it also supports 64-bit integers?

Copy link
Author

RobTillaart commented Sep 5, 2017
edited
Loading

@Ivan-Perez
The String Class could be extended with two functions (one given here)

String::String(uint64_t value, unsigned char base)
{
init();
char buf[1 + 8 * sizeof(unsigned long)];
ul64toa(value, buf, base);
*this = buf;
}

The AVR stdlib does not have a ul64toa() so you need something like this

// straightforward implementation
void ui64toa(uint64_t v, char * buf, uint8_t base)
{
 int idx = 0;
 uint64_t w = 0;
 while (v > 0)
 {
 w = v / base;
 buf[idx++] = (v - w * base) + '0';
 v = w;
 }
 buf[idx] = 0;
 // reverse char array
 for (int i = 0, j = idx - 1; i < idx / 2; i++, j--)
 {
 char c = buf[i];
 buf[i] = buf[j];
 buf[j] = c;
 }
}

A similar function for a signed version void i64toa()

Copy link
Member

This PR was merged in arduino/ArduinoCore-API@3c3b27e , closing here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Labels
Print and Stream class The Arduino core library's Print and Stream classes
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /