Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. My Project
  3. test

test

Scheduled Pinned Locked Moved My Project
3 Posts 2 Posters 380 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Clone Tv
    wrote on last edited by
    #1
    This post is deleted!
    Y 1 Reply Last reply
    0
    • C Clone Tv

      This post is deleted!

      Y Offline
      Y Offline
      Yveaux
      Mod
      wrote on last edited by Yveaux
      #2

      @Clone-Tv can you break it down into separate issues? What are you trying to achieve (share your code, what platform etc)?
      Using 64bit integers on e.g. microcontrollers is non-trivial, but you don't even mention what platform you're targeting...
      Also, please change the subject of your post, 'test' doesn't seem to cover it...

      http://yveaux.blogspot.nl

      1 Reply Last reply
      1
      • C Offline
        C Offline
        Clone Tv
        wrote on last edited by
        #3

        Sorry, that was the test :) the text is irrelevant to the topic.
        But, since we are talking about 64-bit numbers on Arduino-like platforms, I'm ready to translate the code that solves this situation.

        Int64String.h

        #if !defined(INT64STRING_H)
        # define INT64STRING_H 1
        
        # if (defined(ARDUINO) && (ARDUINO >= 100))
        #  include "Arduino.h"
        # else
        #  include "WString.h"
        # endif
        
        String Int64ToString(uint64_t, uint8_t = DEC, bool = false, bool = false);
        String Int64ToString(int64_t, uint8_t = DEC, bool = false);
        uint64_t StringToInt64(String);
        uint64_t StringToInt64(const char*, uint16_t);
        
        #endif
        
        

        Int64String.cpp

        #include "Int64String.h"
        #define base16char(A) ("0123456789ABCDEF"[A])
        
        String Int64ToString(uint64_t value, uint8_t base, bool prefix, bool sign) {
          if (base < 2)
            base = 2;
          else if (base > 16)
            base = 16;
        
          uint8_t i = 64;
          char buffer[66] = {0};
        
          if (value == 0)
            buffer[i--] = '0';
          else {
            uint8_t base_multiplied = 3;
            uint16_t multiplier = base * base * base;
        
            if (base < 16) {
              multiplier *= base;
              base_multiplied++;
            }
            if (base < 8) {
              multiplier *= base;
              base_multiplied++;
            }
            while (value > multiplier) {
              uint64_t q = value / multiplier;
              uint16_t r = value - q * multiplier;
        
              for (uint8_t j = 0; j < base_multiplied; j++) {
                uint16_t rq = r / base;
                buffer[i--] = base16char(r - rq * base);
                r = rq;
              }
              value = q;
            }
        
            uint16_t remaining = value;
            while (remaining > 0) {
              uint16_t q = remaining / base;
              buffer[i--] = base16char(remaining - q * base);
              remaining = q;
            }
          }
        
          if (base == DEC && sign)
            buffer[i--] = '-';
          else if (prefix) {
            if (base == HEX) {
              buffer[i--] = 'x';
              buffer[i--] = '0';
            }
            else if (base == OCT)
              buffer[i--] = '0';
            else if (base == BIN)
              buffer[i--] = 'B';
          }
          return String(&buffer[i + 1]);
        }
        
        String Int64ToString(int64_t value, uint8_t base, bool prefix) {
          bool sign = base == DEC && value < 0;
          uint64_t uvalue = sign ? -value : value;
          return Int64ToString(uvalue, base, prefix, sign);
        }
        
        uint64_t StringToInt64(String str) {
          return StringToInt64(str.c_str(), str.length());
        }
        
        uint64_t StringToInt64(const char *s, uint16_t sz = 0U) {
          uint64_t val = 0ULL;
          if (s == nullptr)
            return val;
        
          if (sz <= 0)
            sz = strlen(s);
        
          if (sz <= 2)
            return val;
          
          uint16_t i = (((s[0] == '0') && ((s[1] == 'x') || (s[1] == 'X'))) ? 2U : 0U);
          for (; i < sz; i++) {
            const char c = s[i];
            if (!isxdigit(c))
              return -1ULL;
            
            val *= 16;
            val += (c >= '0' && c <= '9') ? c - '0' : c - 'A' + 10;
          }
          return val;
        }
        
        

        I gave the sources as an apology for the created topic :)

        1 Reply Last reply
        0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        8

        Online

        12.0k

        Users

        11.2k

        Topics

        113.4k

        Posts


        Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • MySensors
        • OpenHardware.io
        • Categories
        • Recent
        • Tags
        • Popular