Always for me a Big question

New to FreeBASIC? Post your questions here.
dodicat
Posts: 6720
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Always for me a Big question

Postby dodicat » May 10, 2017 19:04

Are you using the original gmp.bi (shipped with fb 24)

...
Last edited by dodicat on May 10, 2017 19:42, edited 1 time in total.
student1347
Posts: 49
Joined: Dec 16, 2011 3:48

Re: Always for me a Big question

Postby student1347 » May 10, 2017 19:26

my gmp.bi was this code below(part of it) (77 k) taken from gmp-6.1.2 from srvaldez (top post) I changed it with yours (29k) and now It works thank you again.

Code: Select all

'' FreeBASIC binding for gmp-6.0.0
''
'' based on the C header files:
''    Definitions for GNU multiple precision functions.   -*- mode: c -*-
''
''   Copyright 1991, 1993-1997, 1999-2014 Free Software Foundation, Inc.
''
''   This file is part of the GNU MP Library.
''
''   The GNU MP Library is free software; you can redistribute it and/or modify
''   it under the terms of either:
''
''     * the GNU Lesser General Public License as published by the Free
''       Software Foundation; either version 3 of the License, or (at your
''       option) any later version.
''
''   or
''
''     * the GNU General Public License as published by the Free Software
''       Foundation; either version 2 of the License, or (at your option) any
''       later version.
''
''   or both in parallel, as here.
''
''   The GNU MP Library is distributed in the hope that it will be useful, but
''   WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
''   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
''   for more details.
''
''   You should have received copies of the GNU General Public License and the
''   GNU Lesser General Public License along with the GNU MP Library.  If not,
''   see https://www.gnu.org/licenses/.
''
'' translated to FreeBASIC by:
''   Copyright © 2015 FreeBASIC development team

#pragma once

#inclib "gmp"

#include once "crt/long.bi"
#include once "crt/stddef.bi"
#include once "crt/stdio.bi"

..................................................

dodicat
Posts: 6720
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Always for me a Big question

Postby dodicat » May 10, 2017 19:41

OK.
I'll delete my gmp.bi from the forum.
Anyway, better to use the most recent freebasic 1.05.
bplus
Posts: 56
Joined: May 01, 2017 15:57

Re: Always for me a Big question

Postby bplus » May 10, 2017 21:23

I have done String Arithmetic at Just Basic forum. Nice exercise! Add, Subtract, Multiply, Divide with number strings as long as you like, no scientific notation. Perfect precision division to any amount of decimal places. Slow as... of course. Also worked on extending sqr to any precision as well.

Check it out if you want, code is there.
student1347
Posts: 49
Joined: Dec 16, 2011 3:48

Re: Always for me a Big question

Postby student1347 » May 12, 2017 12:05

sorry what about the last line of my question "Can I have a digit unit other than binary or decade- with ascci codes(base 256 or base 200) and how ?"
dodicat
Posts: 6720
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Always for me a Big question

Postby dodicat » May 12, 2017 13:02

This could be done faster with a dedicated base change function.
For base 256 the answer would be hex each number (representing each digit) ?
I think this is the standard way, rather than using all the asci+extended asci characters (0 to 266)

Code: Select all





#Include once "gmp.bi"

Function _mod(n1 As String,n2 As String) As String
    Dim As __mpz_struct answer, mn1, mn2
    mpz_init(@answer)
    mpz_init_set_str(@mn1, n1, 10)
    mpz_init_set_str(@mn2, n2, 10)
    mpz_mod(@answer, @mn1, @mn2)
    Dim As ZString Ptr s = mpz_get_str(0, 10, @answer)
    mpz_clear(@answer) : mpz_clear(@mn1) : mpz_clear(@mn2)
    function= Trim(*s)
    deallocate(s)
End Function

Function _div(n1 As String,n2 As String) As String
    Dim As __mpz_struct answer, mn1, mn2
    mpz_init(@answer)
    mpz_init_set_str(@mn1, n1, 10)
    mpz_init_set_str(@mn2, n2, 10)
    mpz_div(@answer, @mn1, @mn2)
    Dim As ZString Ptr s = mpz_get_str(0, 10, @answer)
    mpz_clear(@answer) : mpz_clear(@mn1) : mpz_clear(@mn2)
    function= Trim(*s)
    deallocate(s)
End Function



   
#define range(f,l) int(Rnd*(((l)+1)-(f))+(f))

#macro create(L) 'create a random number
i=string(L," ")
do
    for n as long =0 to L-1
        i[n]=range(48,57)
    next
loop until i[0]<>48
#endmacro

dim as string i
create(5000) 'digits
print "Number is: "
print i
print
dim as string m,d,h,result
dim as string b="256"
do
    d=_div(i,b)
    m=_mod(i,b)
    result=" " + hex(valint(m),2)+result
    i=d
  loop until i="0"
  print
  print "base ";b
  print trim(result)
 
  print
  sleep
 
   

 
 
student1347
Posts: 49
Joined: Dec 16, 2011 3:48

Re: Always for me a Big question

Postby student1347 » May 12, 2017 17:12

Dear dodicat as you know one of the aims of using big bases is to make the number as small as possible(showing big numbers with few characters)if we use hex then there is no difference between hex and base 256 in length.I want to show up to 256 using only one character not two characters like hex.
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: Always for me a Big question

Postby Tourist Trap » May 12, 2017 17:38

student1347 wrote:I want to show up to 256 using only one character not two characters like hex.

Read this topic, we have been talking about that with dodicat and many people some time ago :
viewtopic.php?p=210096#p210096

Code: Select all

'                                                         .---.
'                                                         | 0 |
'                                                         .---.
Const As ULongInt U_MAXULONGINT = 2^64
Const As ULongInt U_MAXLONGINT = 2^63
Const As ULongInt _MAXULONGINT = U_MAXULONGINT - 1
Const As LongInt _MAXLONGINT = U_MAXLONGINT-1
'                                                         .---.
'                                                         | 1 |
'                                                         .---.
Type BASEnCOMPACT
   Declare Constructor(ByVal BASE_ As UByte = 2, NUMBER_ As ULongInt = 0)
   
   Declare Property BSE() As UByte                     ''*
   Declare Property BSE(As UByte)                      ''*
   Declare Property NUMBER() As ULongInt
   Declare Property NUMBER(As ULongInt)
   Declare Property GETTEXT() As String
   Declare Property REPRESENTATION() As String
   Declare Property GETFACTOR(ByVal Index As UByte) As UByte
   
   Declare Function GreaterExp() As LongInt
   Declare Function BaseExp(ByRef Exp_ As LongInt, _
                            ByVal Num_ As ULongInt=1) As ULongInt
   Declare Function BaseRep(Rep_() As UByte, _
                            ByVal Num_ As ULongInt=1) As ULongInt
   Private :
    As UByte _BASE = 2
    As ULongInt _NUMBER = 0
     As UByte _REPRESENTATION(63)
    As LongInt _EXPONENT = 0
    As ULongInt _ADDVALUE = 0
    As String _TEXT = "2E0+A"
    As LongInt Ptr _EXPONENTLIST
    As ULongInt Ptr _FACTORLIST
End Type 'BASEnCOMPACT
Constructor BASEnCOMPACT(ByVal BASE_ As UByte = 2, ByVal NUMBER_ As ULongInt = 0)
    This._BASE = BASE_
    This._NUMBER = NUMBER_
   For _index As UByte = 0 To 63
       This._REPRESENTATION(_index) = 0
   Next _index
   Select Case NUMBER_
      Case 0
          This._EXPONENT = -1
          This._ADDVALUE = 0
          This._TEXT = "0"
      Case Else
          This.BaseExp(This._EXPONENT, NUMBER_)
          This._ADDVALUE = NUMBER_ - BASE_^This._EXPONENT
          This._TEXT = This.GETTEXT
   End Select 'NUMBER_   
End Constructor 'BASEnCOMPACT(UBYTE[=2],ULONGINT[=0])
Property BASEnCOMPACT.BSE() As UByte
   Return This._BASE
End Property 'Get UBYTE:=BASEnCOMPACT.BSE()
Property BASEnCOMPACT.BSE(ByVal setBASE As UByte)
    This._BASE = setBASE
    This.NUMBER = This._NUMBER
End Property 'Set BASEnCOMPACT.BSE()
Property BASEnCOMPACT.NUMBER() As ULongInt
   Return This._NUMBER
End Property 'Get ULONGINT:=BASEnCOMPACT.NUMBER()
Property BASEnCOMPACT.NUMBER(ByVal setNUMBER As ULongInt)
    This._NUMBER = setNUMBER
    ''Fill fields accordingly   
   Select Case setNUMBER
      Case 0
          This._EXPONENT = -1
          This._ADDVALUE = 0
          This._TEXT = "0"
      Case Else
          This.BaseExp(This._EXPONENT, setNUMBER)
          This._ADDVALUE = setNUMBER - This._BASE^This._EXPONENT
          This._TEXT = This.GETTEXT
   End Select 'setNUMBER
End Property 'Set ULONGINT:=BASEnCOMPACT.NUMBER()
Property BASEnCOMPACT.GETTEXT() As String
   Dim As String S
    S = Str(This._BASE)
    S &= "^"& Str(This._EXPONENT)
    S &= IIf(This._ADDVALUE=0, "", "+"& This._ADDVALUE)
   Return S
End Property 'Get STRING:=BASEnCOMPACT.GETTEXT()
Property BASEnCOMPACT.REPRESENTATION() As String
   For _index As UByte = 0 To 63
       This._REPRESENTATION(_index) = 0
   Next _index
    This.BaseRep(This._REPRESENTATION(), This._NUMBER)
   Dim As String R = "b"& This._BASE
    R &= "<+"
   For _index As UByte = 0 To 63
      If This._REPRESENTATION(_index)<>0 Then
          R &= This._REPRESENTATION(_index) & "*" & "^" & _index & "+"
      End If
   Next _index
    R &= ">"
   Return R
End Property 'Get BASEnCOMPACT.REPRESENTATION()
Property BASEnCOMPACT.GETFACTOR(ByVal Index As Ubyte) As UByte
   Return This._REPRESENTATION(Index)
End Property '
Function BASEnCOMPACT.GreaterExp() As LongInt
   Dim As UByte index = 63
    This.BaseRep(This._REPRESENTATION(), This._NUMBER)
   
   While Not (index<=0 OrElse This._REPRESENTATION(index))
       index -= 1
   Wend 'index>0

   Return index
End Function 'LONGINT:=BASEnCOMPACT.GreaterExp()
Function BASEnCOMPACT.BaseExp(ByRef Exp_ As LongInt, _
                              ByVal Num_ As ULongInt=1) As ULongInt
   Exp_ = 0
   While Num_>=This._BASE
          Exp_ += 1
          Num_ \= This._BASE
   Wend 'Num_>=This._BASE

   Return Num_ - This._BASE^Exp_
End Function 'ULONGINT:=BASEnCOMPACT.BaseExp(REF_UINTEGER,ULONGINT[=1])
Function BASEnCOMPACT.BaseRep(Rep_() As UByte, _
                              ByVal Num_ As ULongInt=1) As ULongInt
   Dim As UByte _Exp = 0
   Dim As ULongInt _Num = Num_
   Dim As ULongInt _Rem = Num_
   
   For _index As UByte = 0 To 63
       Rep_(_index) = 0
   Next _index
   
   While _Rem >= This._BASE
       _Rem = _Num
       _Exp = 0
      While _Num >= This._BASE
          _Exp += 1
          _Num = _Num \ This._BASE
      Wend     
      If _Exp = 0 Then
          Rep_(_Exp) += _Rem
      Else
          Rep_(_Exp) += 1
           _Num = _Rem - This._BASE^_Exp
      EndIf
   Wend

   Return 0
End Function 'ULONGINT:=BASEnCOMPACT.BaseRep(REF_UBYTE(),ULONGINT[=1])
'                                                         .---.
'                                                         | 2 |
'                                                         .---.
Function Base62ToNotation(ByVal Cpn As BASEnCOMPACT) As String
   Var initialBASE = Cpn.BSE
   If initialBASE<>62 Then
      Cpn.BSE=62
   EndIf
   Dim As String f62 = ""
   For _index As Byte = Cpn.GreaterExp() To 0 Step -1
      Select Case As Const Cpn.GETFACTOR(_index)
         Case 0 To 9
             f62 &= Chr(48+Cpn.GETFACTOR(_index))
         Case 10 To 23
             f62 &= Chr(65+Cpn.GETFACTOR(_index)-10)
         Case 24
             f62 &= Chr(64)
         Case 25 To 35
             f62 &= Chr(65+Cpn.GETFACTOR(_index)-10)
         Case 36 To 61
             f62 &= Chr(97+Cpn.GETFACTOR(_index)-36)
      End Select 'As Const Cpn.GETFACTOR(_index)     
   Next '_index
   Cpn.BSE = InitialBASE

   Return f62
End Function 'STRING:=Base62ToNotation(STRING)
'                                                         .---.
'                                                         | 3 |
'                                                         .---.
Function SeedMapping(byval Seed as ULongInt) As ULongInt
    Randomize Seed
    Return Rnd()*1e+17
End Function 'ULONGINT:=SeedMapping(ULONGINT)
'                                                         .---.
'                                                         | 4 |
'                                                         .---.
'------------------------------------------------------------
'                          DEMO
'------------------------------------------------------------
Dim As String NUM
Dim As BASEnCOMPACT Cpn = BASEnCOMPACT(2, 77777)

Do
   Cls
   Locate 1,1
   ? "DECIMAL NUMBER       " ; Cpn.NUMBER;
   ? "               REPRESENTATION BASE  " ; Cpn.BSE   
   ? "--------------";
   ? "                           -------------------"
   ?
   ? "REPRESENTATION 1     " ; Cpn.GETTEXT
   ? "----------------"
   ?
   ? "REPRESENTATION 2"
   ? "----------------"
   ? Cpn.REPRESENTATION
   ?
   ? "REPRESENTATION 3 (BASE 62)"
   ? "--------------------------"
   ? Base62ToNotation(Cpn)

   Locate 24, 10 : Input "New decimal number OR [Q] to quit :"; NUM
   Cpn.NUMBER = CUlngInt(NUM)
Loop Until LCase (NUM) = "q"
'------------------------------------------------------------
dodicat
Posts: 6720
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Always for me a Big question

Postby dodicat » May 12, 2017 17:50

student1347 wrote:Dear dodicat as you know one of the aims of using big bases is to make the number as small as possible(showing big numbers with few characters)if we use hex then there is no difference between hex and base 256 in length.I want to show up to 256 using only one character not two characters like hex.

Then use the ascii(0 to 255)
It is a simple tweak.

(It beeps on printing due to chr(7)




Code: Select all

#Include once "gmp.bi"

Function convert(Byval Base10 As String ,b As String) As String
    Dim As zstring Ptr s
    Dim As __mpz_struct answer,id,divd,modd,bb,zero
    mpz_init2( @answer,0)
    mpz_init2( @id,0)
    mpz_init2( @divd,0)
    mpz_init2( @modd,0)
    mpz_init2( @bb,0)
    mpz_init2( @zero,0)
    mpz_init_set_str( @id,Base10,10)
    mpz_init_set_str( @bb,b,10)
    Dim As String acc
    Do
        mpz_div(@divd,@id,@bb)
        mpz_mod(@modd,@id,@bb)
        s= mpz_get_str(0, 10, @modd)
        'acc= Hex(Valint(*s),2)+" "+acc
         acc= chr(Valint(*s))+acc
        Mpz_set(@id,@divd)
    Loop Until  Mpz_cmp(@divd,@zero)=0
    Function= acc
    mpz_clear(@answer) : mpz_clear(@id) : mpz_clear(@divd)
    mpz_clear(@modd) : mpz_clear(@bb) : mpz_clear(@zero)
    Deallocate s
End Function

#define range(f,l) int(Rnd*(((l)+1)-(f))+(f))

#macro create(L) 'create a random number
i=String(L," ")
Do
    For n As Long =0 To L-1
        i[n]=range(48,57)
    Next
Loop Until i[0]<>48
#endmacro
dim as string i

create(5000)
print "Decimal"
print i
print
print "ascii"
print convert(i,"256")
sleep
 
student1347
Posts: 49
Joined: Dec 16, 2011 3:48

Re: Always for me a Big question

Postby student1347 » May 12, 2017 18:14

Thank you Tourist trap for showing the good topic and also dodicat for answering me with example and with patiance . (novice)
student1347
Posts: 49
Joined: Dec 16, 2011 3:48

Re: Always for me a Big question

Postby student1347 » May 13, 2017 15:23

Sorry Dear dodicat Is it possible with some changes in your above program make it to change base 256 to base 10 or hex or 2 ? Thank you in advance.
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: Always for me a Big question

Postby Tourist Trap » May 13, 2017 16:50

student1347 wrote: change base 256 to base 10 or hex or 2 ? Thank you in advance.

It seems to be limited to base 36 with STROULL (in my system at least), so here is an example, but it wont give you any for base 255 :

Code: Select all

#include "crt.bi"

? "base 36", 36, "-->", strtoull(@"B", 0, 36)

sleep

By the way I've done some extension to my old rusty base converter and it should support base 255 now. What I can say is that once you have your string :
  • chr(200) & chr(23) & .....,
it means that your number is equal to
  • 200*255^n + 23*255^(n-1) + ...
That's potentially very big, and if the previous steps are easy (changing a string in chr(...) & chr(...) & ...) , the final addition is a job for GMP. And this is where I can not go, so let's wait for dodi's advice as usual!

Code: Select all

'                                                         .---.
'                                                         | 0 |
'                                                         .---.
'                                                         .---.
'                                                         | 1 |
'                                                         .---.
Type BasEnCOMPACT
   declare constructor(ByVal BasE_ as UInteger = 2, NUMBER_ as ULongInt = 0)
   declare property BSE() as UInteger
   declare property BSE(as UInteger)
   declare property NUMBER() as ULongInt
   declare property NUMBER(as ULongInt)
   declare property GETTEXT() as String
   declare property REPRESENTATION() as String
   declare property GETFACTOR(ByVal Index as UInteger) as UInteger
   declare function GreaterExp() as LongInt
   declare function BaseExp(   ByRef Exp_ as LongInt, _
                        ByVal Num_ as ULongInt=1) _
                        as ULongInt
   declare function BaseRep(   Rep_() as UInteger, _
                        ByVal Num_ as ULongInt=1) as ULongInt
      as UInteger      _BasE      => 2
      as ULongInt      _NUMBER      => 0
      as UInteger      _REPRESENTATION(255)
      as LongInt      _EXPONENT   => 0
      as ULongInt      _ADDVALUE   => 0
      as String      _TEXT      => "2E0+A"
      as LongInt Ptr   _EXPONENTLIST
      as ULongInt Ptr   _FACTORLIST
end Type 'BasEnCOMPACT
constructor BasEnCOMPACT(ByVal BasE_ as UInteger = 2, ByVal NUMBER_ as ULongInt = 0)
   THIS._BasE = BasE_
   THIS._NUMBER = NUMBER_
   
   for _index as UInteger = 0 To 255
      THIS._REPRESENTATION(_index) = 0
   next _index
   
   select case NUMBER_
      case 0
         THIS._EXPONENT   => -1
         THIS._ADDVALUE   => 0
         THIS._TEXT      => "0"
      case Else
         THIS.BaseExp(THIS._EXPONENT, NUMBER_)
         THIS._ADDVALUE   => NUMBER_ - BasE_^THIS._EXPONENT
         THIS._TEXT      => THIS.GETTEXT
   end select 'NUMBER_   
end constructor 'BasEnCOMPACT(UInteger[=2],ULONGINT[=0])
property BasEnCOMPACT.BSE() as UInteger
   return THIS._BasE
end property 'Get UInteger:=BasEnCOMPACT.BSE()
property BasEnCOMPACT.BSE(ByVal setBasE as UInteger)
   THIS._BasE = setBasE
   THIS.NUMBER = THIS._NUMBER
end property 'Set BasEnCOMPACT.BSE()
property BasEnCOMPACT.NUMBER() as ULongInt
   return THIS._NUMBER
end property 'Get ULONGINT:=BasEnCOMPACT.NUMBER()
property BasEnCOMPACT.NUMBER(ByVal setNUMBER as ULongInt)
   THIS._NUMBER = setNUMBER
   ''Fill fields accordingly   
   select case setNUMBER
      case 0
         THIS._EXPONENT = -1
         THIS._ADDVALUE = 0
         THIS._TEXT = "0"
      case Else
         THIS.BaseExp(THIS._EXPONENT, setNUMBER)
         THIS._ADDVALUE = setNUMBER - THIS._BasE^THIS._EXPONENT
         THIS._TEXT = THIS.GETTEXT
   end select 'setNUMBER
end property 'Set ULONGINT:=BasEnCOMPACT.NUMBER()
property BasEnCOMPACT.GETTEXT() as String
   dim as String S
   
   S = Str(THIS._BasE)
   S &= "^"& Str(THIS._EXPONENT)
   S &= IIf(THIS._ADDVALUE=0, "", "+"& THIS._ADDVALUE)
   
   return S
end property 'Get STRING:=BasEnCOMPACT.GETTEXT()
property BasEnCOMPACT.REPRESENTATION() as String
   for _index as UInteger = 0 To 255
      THIS._REPRESENTATION(_index) = 0
   next _index
   THIS.BaseRep(THIS._REPRESENTATION(), THIS._NUMBER)

   dim as String R = "b"& THIS._BasE
   R &= "<+"

   for _index as UInteger = 0 To 255
      If THIS._REPRESENTATION(_index)<>0 Then
         R &= THIS._REPRESENTATION(_index) & "*" & "^" & _index & "+"
      end If
   next _index
   R &= ">"
   
   return R
end property 'Get BasEnCOMPACT.REPRESENTATION()
property BasEnCOMPACT.GETFACTOR(ByVal Index as UInteger) as UInteger
   return THIS._REPRESENTATION(Index)
end property '
function BasEnCOMPACT.GreaterExp() as LongInt
   dim as UInteger index = 255
   THIS.BaseRep(THIS._REPRESENTATION(), THIS._NUMBER)
   
   while Not (index<=0 OrElse THIS._REPRESENTATION(index))
      index -= 1
   wend 'index>0
   
   return index
end function 'LONGINT:=BasEnCOMPACT.GreaterExp()
function BasEnCOMPACT.BaseExp(ByRef Exp_ as LongInt, _
                              ByVal Num_ as ULongInt=1) as ULongInt
   Exp_ = 0
   while Num_>=THIS._BasE
      Exp_ += 1
      Num_ \= THIS._BasE
   wend 'Num_>=THIS._BasE
   
   return Num_ - THIS._BasE^Exp_
end function 'ULONGINT:=BasEnCOMPACT.BaseExp(REF_UINTEGER,ULONGINT[=1])
function BasEnCOMPACT.BaseRep(   Rep_() as UInteger, _
                        ByVal Num_ as ULongInt=1) as ULongInt
   dim as UInteger _Exp = 0
   dim as ULongInt _Num = Num_
   dim as ULongInt _Rem = Num_
   
   for _index as UInteger = 0 To 255
      Rep_(_index) = 0
   next _index
   
   while _Rem >= THIS._BasE
      _Rem = _Num
      _Exp = 0
      while _Num >= THIS._BasE
         _Exp += 1
         _Num = _Num \ THIS._BasE
      wend     
      If _Exp = 0 Then
         Rep_(_Exp) += _Rem
      Else
         Rep_(_Exp) += 1
         _Num = _Rem - THIS._BasE^_Exp
      endIf
   wend
   
   return 0
end function 'ULONGINT:=BasEnCOMPACT.BaseRep(REF_UInteger(),ULONGINT[=1])
'                                                         .---.
'                                                         | 2 |
'                                                         .---.
function Base62ToNotation(ByVal Cpn as BasEnCOMPACT) as String
   Var initialBasE = Cpn.BSE
   
   If initialBasE<>62 Then
      Cpn.BSE=62
   endIf
   
   dim as String f62 = ""
   
   if Cpn.GreaterExp()=0 then
      f62 = Chr(Cpn.NUMBER)
   else
      for _index as integer = Cpn.GreaterExp() To 0 Step -1
         select case as Const Cpn.GETFACTOR(_index)
            case 0 To 9
               f62 &= Chr(48+Cpn.GETFACTOR(_index))
            case 10 To 23
               f62 &= Chr(65+Cpn.GETFACTOR(_index)-10)
            case 24
               f62 &= Chr(64)
            case 25 To 35
               f62 &= Chr(65+Cpn.GETFACTOR(_index)-10)
            case 36 To 61
               f62 &= Chr(97+Cpn.GETFACTOR(_index)-36)
         end select 'as Const Cpn.GETFACTOR(_index)     
      next '_index
   endIf
   Cpn.BSE = InitialBasE
   
   return f62
end function 'STRING:=Base62ToNotation(STRING)

function Base255ToNotation(ByVal Cpn as BasEnCOMPACT) as String
   Var initialBasE = Cpn.BSE
   
   If initialBasE<>255 Then
      Cpn.BSE=255
   endIf
   
   dim as String f255 = ""
   
   if Cpn.GreaterExp()=0 then
      f255 = Chr(Cpn.NUMBER)
   else
      for _index as integer = Cpn.GreaterExp() To 0 Step -1
         f255 &= Chr(Cpn.GETFACTOR(_index))
      next '_index
   endIf
   Cpn.BSE = InitialBasE
   
   return f255
end function 'STRING:=Base255ToNotation(STRING)

'                                                         .---.
'                                                         | 3 |
'                                                         .---.
function SeedMapping(byval Seed as ULongInt) as ULongInt
   Randomize Seed
   return Rnd()*1e+17
end function 'ULONGINT:=SeedMapping(ULONGINT)
'                                                         .---.
'                                                         | 4 |
'                                                         .---.


'------------------------------------------------------------M
dim as String NUM
dim as BasEnCOMPACT Cpn = BasEnCOMPACT(255, 258)

do
   cls
   locate 1,1
   ? "DECIMAL NUMBER       " ; Cpn.NUMBER;
   ? "               REPRESENTATION BasE  " ; Cpn.BSE   
   ? "--------------";
   ? "                           -------------------"
   ?
   ? "REPRESENTATION 1     " ; Cpn.GETTEXT
   ? "----------------"
   ?
   ? "REPRESENTATION 2"
   ? "----------------"
   ? Cpn.REPRESENTATION
   ?
   ? "REPRESENTATION 3 (BasE 62)"
   ? "--------------------------"
   ? Base62ToNotation(Cpn)
   ?
   ? "REPRESENTATION 4 (BasE 255)"
   ? "--------------------------"
   ? Base255ToNotation(Cpn)
   
   locate 24, 10 : input "New decimal number OR [Q] to quit :"; NUM
   Cpn.NUMBER = CUlngInt(NUM)
   '
loop Until Lcase (NUM) = "q"


'------------------------------------------------------------E
'(eof)
frisian
Posts: 249
Joined: Oct 08, 2009 17:25

Re: Always for me a Big question

Postby frisian » May 20, 2017 21:20

srvaldez wrote:thank you frisian for the update, perhaps you should post it in the tips & tricks section?

I have updated my GMP_INT.BI version in the tips and tricks section.
http://www.freebasic.net/forum/viewtopic.php?f=7&t=25684
student1347
Posts: 49
Joined: Dec 16, 2011 3:48

Re: Always for me a Big question

Postby student1347 » May 23, 2017 16:41

Special thanks to frisian ,srvaldez,dear dodicat,Mrswiss,badidea,bplus,Tourist trap,Makoto WANTANABE for thier answers and help.

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 5 guests