Fractional base M to N conversion

Function [seqY, remX] = baseNtobaseM(seqX, N, M, K) converts fractional seqX in base N to fractional seqY upto K fractional points

Al momento, stai seguendo questo contributo

------------------------------------------------------------------------------------------------
Title : Converting a fractional sequence in given base to another base
Author : Amir R. Forouzan
Email : a.forouzan@eng.ui.ac.ir
Company : University of Isfahan
Created on : 3 Feb. 2025
------------------------------------------------------------------------------------------------
Function : baseNtobaseM
Purpose : Converts a fractional number in base N to a number in base M up to K fractional points.
Inputs :
- seqX : Vector representing the input number in base N. Each element seqX(k)
represents the k-th fractional point of X and is a non-negative integer < N.
- N : The base of the input number seqX.
- M : The base to which the input number seqX is to be converted.
- K : Number of fractional points to which the output number seqY is to be computed.
Outputs :
- seqY : Vector representing the output number in base M. Each element seqY(k)
represents the k-th fractional point of Y and is a non-negative integer < M.
- remX : Vector representing the remainder in base N. Each element remX(k)
represents the k-th fractional point of R and is a non-negative integer < N.
Description:
seqX represents X = (0.seqX(1) seqX(2) seqX(3) ...) in base N.
seqY represents Y = (0.seqY(1) seqY(2) seqY(3) ...) in base M.
remX represents R = (0.remX(1) remX(2) remX(3) ...) in base N.
The function converts seqX to seqY and calculates remX such that X = Y + R / N^K.
Example :
Converting X = 0.5 in base 2 to base 3 up to 4 fractional points.
X in base 2 is represented by seqX = [1] and N = 2, M = 3, K = 4.
[seqY, remX] = baseNtobaseM([1], 2, 3, 4)
Results:
seqY =
1
1
1
1
remX =
1
Thus Y = 1/3 + 1/9 + 1/27 + 1/81 and R = 1/2.
We see that Y + R / 81 = 0.5 as expected.
Code:
Y = 1/3 + 1/9 + 1/27 + 1/81;
R = 1/2;
result = Y + R / 81
result =
0.5000

Cita come

Amir R. Forouzan (2025). Fractional base M to N conversion (https://www.mathworks.com/matlabcentral/fileexchange/<...>), MATLAB Central File Exchange. Retrieved February 3, 2025.

Informazioni generali

Compatibilità della release di MATLAB

  • Compatibile con qualsiasi release

Compatibilità della piattaforma

  • Windows
  • macOS
  • Linux
Versione Pubblicato Note della release Action
1.0.2

Minor change in function definition line.

1.0.1

Minor correction in summary and description

1.0.0