logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

FBB::LDC - Converts (large) digital values to characters

Author

       Frank B. Brokken (f.b.brokken@rug.nl).

libbobcat-dev_6.07.01                               2005-2025                                  FBB::LDC(3bobcat)

Bobcat

       Bobcat is an acronym of `Brokken’s Own Base Classes And Templates’.

Bobcat Project Files

       o      https://fbb-git.gitlab.io/bobcat/: gitlab project page;

       Debian Bobcat project files:

       o      libbobcat6: debian package containing the shared library, changelog and copyright note;

       o      libbobcat-dev: debian package containing the static library, headers, manual pages, and  developer
              info;

Bugs

       None Reported.

Constructors

       o      LDC():
              The default constructor initializes its value to 0;

       o      LDC(std::stringconst&hexNr,size_tradix=10):
              The bytes of the string hexNr contains the character representation of a hexadecimal value,  which
              is  converted  to  its  equivalent  representation using the radix number system. The string hexNr
              should not begin with 0x, but its first character should be the value’s  most  significant  digit.
              E.g., LDCldc{"12345"} is converted to decimal 74565 (in this example "12345" is first converted
              to  a  std::string,  which  is  then passed on to ldc’s constructor). hexNr may not be empty or an
              exception is thrown;

       o      LDC(std::stringconst&hexNr,std::stringconst&digits):
              Same as the previous constructor, but the number system is inferred from  digits’s  length,  using
              its  first  character to represent value 0, and its last character to represent the final digit of
              the inferred number system;

       o      LDC(size_tnBytes,charconst*bytes,size_tradix=10):
              The bytes of the string bytes contains the character representation of a hexadecimal value,  which
              is  converted to its equivalent representation using radix. The string bytes should not begin with
              0x, but its first character should be the value’s most significant digit. E.g., LDC{5,"12345"}
              is converted to decimal 74565. nBytes must be at least 1 or an exception is thrown;

       o      LDC(size_tnBytes,charconst*bytes,std::stringconst&digits):
              Same as the previous constructor, but the number system and the digit characters are inferred from
              digits;

       o      LDC(BigIntconst&bigInt,size_tradix=10):
              BigInt’s value is converted to its equivalent representation using radix;

       o      LDC(BigIntconst&bigInt,std::stringconst&digits):
              Same as the previous constructor, but the number system and the digit characters are inferred from
              digits.

       Copy and move constructors (and assignment operators) are available.

Description

       Objects of the class LDC (Large Digital Converter) convert (large) digital values (like values handled by
       the class BigInt (cf. bigint(3bobcat))) to character representations using radices from 2 through 36. For
       radices  larger  than 10 letters are used, using a through z to represent the (decimal) values 10 through
       36. When specifying radices outside of this range an exception is thrown.

       Alternatively, the digits of the converted number can be provided in a std::string  argument,  where  the
       string’s  first  character  (at index 0) is used for value 0, the next character for value 1, etc., until
       the string’s last character. In that case the string’s length defines the number system that is used  for
       converting  the  (large)  digital  value.  Usually  the first 10 characters will be "0123456789", but LDC
       doesn’t enforce that. Instead, any series of characters can be specified, in which case the character  at
       index  idx  is  used  to  represent  value  idx  in  the  converted  value  string. E.g., when specifying
       "abcdefghij" the hexadecimal value "deadbeef" is converted to "dhdfjciffj" instead of "3735928559", which
       is the normally used decimal digit representation. Digit strings must at least contain two characters  or
       an exception is thrown.

Example

       #include <iostream>

       #include <bobcat/ldc>

       using namespace std;
       using namespace FBB;

       int main(int argc, char **argv)
       {
           string value = "1122334455667788aabbcc";

           size_t radix = 10;

           LDC digits{ value, "0123456789ABCDEF" };

           LDC ldc{ value, radix };

           cout << "radix = " << radix << "\n"
                   "value = " << value << "\n"
                   "digits: " << digits << "\n"
                   "   LDC: " << ldc << "\n"
                   "        " << ldc(3, ’.’) << ’\n’;
       }

       // shows:
       //     radix = 10
       //     value = 1122334455667788aabbcc
       //     digits: 1122334455667788AABBCC
       //        LDC: 20713245101768454273940428
       //             20.713.245.101.768.454.273.940.428

Files

bobcat/ldc - defines the class interface

Free Function In The Fbb Namespace

       o      std::ostream&operator<<(std::ostream&out,LDCconst&ldc):
              The insertion operator inserts the converted value into out, returning out.

Inherits From

       -

Member Functions

       o      voidset(std::stringconst&hexNr,size_tradix=10):
              The LDC object’s converted value is set to the hexadecimal value hexNr, converted to number system
              radix. hexNr may not be empty or an exception is thrown ;

       o      voidset(std::stringconst&hexNr,std::stringconst&digits):
              Same  as  the  previous  member,  but  converting hexNr to the number system and number characters
              defined by digits;

       o      voidset(size_tnBytes,charconst*bytes,size_tradix=10):
              The LDC object’s converted value is set to the hexadecimal value stored in  the  nBytes  bytes  of
              bytes, converted to number system radix. nBytes must be at least 1 or an exception is thrown;

       o      voidset(size_tnBytes,charconst*bytes,std::stringconst&digits):
              Same  as  the  previous  member,  but  converting bytes to the number system and number characters
              defined by digits;

       o      std::stringconst&str()const:
              The LDC object’s converted value is returned;

       o      voidswap(LDC&other):
              The other LDC  object and the current LDC object are swapped.

Name

       FBB::LDC - Converts (large) digital values to characters

Namespace

FBB
       All  constructors,  members,  operators  and manipulators, mentioned in this man-page, are defined in the
       namespace FBB.

Overloaded Operators

       In addition to the standard copy- and move-assignment operators the following operators are available:

       o      LDC&operator=(std::stringconst&hexNr):
              The  operator’s  rhs is the character representation of a hexadecimal number, which is assigned to
              the LDC object. The object converts hexNr to its decimal representation (see also the members set,
              below).
              Example:

              LDC ldc;            // initialized with some value
              ldc = "12345";      // assign a new value
              cout << ldc << ’\n’ // displays 74655

              The rhs value may not be empty or an exception is thrown;

       o      std::stringoperator()(size_tpower,charsep=’\’’)const:
              The converted value is returned using separator sep before each multiple of  power  digits.  E.g.,
              when ldc contains the converted value 3735928559 then ldc(3) returns the string 3.735.928.559.

See Also

bobcat(7)

Synopsis

#include<bobcat/LDC>
       Linking option: -lbobcat

See Also