# FBB::LDC(3bobcat)

## Convert (large) digital values to characters
(libbobcat-dev_6.02.02)

## 2005-2022

## NAME

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

## SYNOPSIS

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

## 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.

## NAMESPACE

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

## INHERITS FROM

-

## CONSTRUCTORS

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

- LDC(std::string const &hexNr, size_t radix = 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., LDC ldc{ "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;

- LDC(std::string const &hexNr, std::string const &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;

- LDC(size_t nBytes, char const *bytes, size_t radix = 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;

- LDC(size_t nBytes, char const *bytes, std::string const &digits):
  Same as the previous constructor, but the number system and the digit characters are inferred from digits;

- LDC(BigInt const &bigInt, size_t radix = 10):
  BigInt's value is converted to its equivalent representation using radix;

- LDC(BigInt const &bigInt, std::string const &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.

## OVERLOADED OPERATORS

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

- LDC &operator=(std::string const &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;

- std::string operator()(size_t power, char sep = '\'') 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.

## FREE FUNCTION IN THE FBB NAMESPACE

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

## MEMBER FUNCTIONS

- void set(std::string const &hexNr, size_t radix = 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 ;

- void set(std::string const &hexNr, std::string const &digits):
  Same as the previous member, but converting hexNr to the number system and number characters defined by digits;

- void set(size_t nBytes, char const *bytes, size_t radix = 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;

- void set(size_t nBytes, char const *bytes, std::string const &digits):
  Same as the previous member, but converting bytes to the number system and number characters defined by digits;

- std::string const &str() const:
  The LDC object's converted value is returned;

- void swap(LDC &other):
  The other LDC object and the current LDC object are swapped.

## 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

## SEE ALSO

bobcat(7)

## BUGS

None Reported.

## BOBCAT PROJECT FILES

- https://fbb-git.gitlab.io/bobcat/: gitlab project page;
- bobcat_6.02.02-x.dsc: detached signature;
- bobcat_6.02.02-x.tar.gz: source archive;
- bobcat_6.02.02-x_i386.changes: change log;
- libbobcat1_6.02.02-x_*.deb: debian package containing the libraries;
- libbobcat1-dev_6.02.02-x_*.deb: debian package containing the libraries, headers and manual pages;

## BOBCAT

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

## COPYRIGHT

This is free software, distributed under the terms of the GNU General Public License (GPL).

## AUTHOR

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