,原创用MATLAB完成二进制,十进制,十六进制之间的转换,对滤波器的抽头系数处理非常有效

(原创)用MATLAB完成二进制,十进制,十六进制之间的转换,对滤波器的抽头系数处理非常有效(MATLAB)

虽然这些都是在帮助上找到的(如help num2hex),但有些人不懂MATLAB会有这些功能,而不懂得充分利用,所以贴出来共享,对于用FPGA做数字信号处理非常有效!

BIN2NUM Binary string to numeric array conversion

X = BIN2NUM(Q,B) converts binary string B to numeric matrix X. The

attributes of the number are specified by quantizer object Q. If B is a

cell array containing binary strings, then X will be a cell array of the

same dimension containing numeric matrices. The fixed-point binary

representation is two\'s complement. The floating-point binary

representation is IEEE style.

If there are fewer binary digits than are necessary to represent the number,

then fixed-point zero-pads on the left, and floating-point zero-pads on the

right.

[X1,X2,...] = BIN2NUM(Q,B1,B2,...) converts binary strings B1, B2,... to

numeric matrices X1, X2, ....

BIN2NUM and NUM2BIN are inverses of each other, except that NUM2BIN

always returns a column.

For example, all of the 3-bit fixed-point two\'s-complement numbers in

fractional form are given by:

q = quantizer([3 2]);

b = [\'011 111\'

\'010 110\'

\'001 101\'

\'000 100\'];

x = bin2num(q,b)

x =

0.7500 -0.2500

0.5000 -0.5000

0.2500 -0.7500

0 -1.0000

///////////////////////////////////////////////////////////////////////////

NUM2BIN Number to binary string

B = NUM2BIN(Q,X) converts numeric matrix X to binary string B. The

attributes of the number are specified by quantizer object Q. If X

is a cell array containing numeric matrices, then B will be a cell

array of the same dimension containing binary strings. The

fixed-point binary representation is two\'s complement. The

floating-point binary representation is IEEE style.

[B1,B2,...] = NUM2BIN(Q,X1,X2,...) converts numeric matrices X1, X2,

... to binary strings B1, B2, ....

NUM2BIN and BIN2NUM are inverses of each other, except that NUM2BIN

always returns a column.

For example, all of the 3-bit fixed-point two\'s complement numbers in

fractional form are given by:

q = quantizer([3 2]);

x = [0.75 -0.25

0.50 -0.50

0.25 -0.75

0 -1 ];

b = num2bin(q,x)

b =

011

010

001

000

111

110

101

100

///////////////////////////////////////////////////////////////////

HEX2BIN Convert hexadecimal strings to binary strings

B = HEX2BIN(Q,H) converts hexadecimal strings vectorized in a column H to

binary strings B. The wordlength is derived from quantizer Q. This is a

private function that is used by NUM2BIN.

Example:

q = quantizer(\'fixed\',[8 7]);

h = [\'ff\'; \'fe\'];

b = hex2bin(q,h)

b =

11111111

11111110

////////////////////////////////////////////////////////////////////////

NUM2HEX Number to hexadecimal string

H = NUM2HEX(Q,X) converts numeric matrix X to hexadecimal string H.

The attributes of the number are specified by Quantizer object Q.

If X is a cell array containing numeric matrices, then H will be a

cell array of the same dimension containing hexadecimal strings.

The fixed-point hexadecimal representation is two\'s complement. The

floating-point hexadecimal representation is IEEE style.

[H1,H2,...] = NUM2HEX(Q,X1,X2,...) converts numeric matrices X1, X2,

... to hexadecimal strings H1, H2, ....

NUM2HEX and HEX2NUM are inverses of each other, except that NUM2HEX

always returns a column.

For example, all of the 4-bit fixed-point two\'s complement numbers in

fractional form are given by:

q = quantizer([4 3]);

x = [0.875 0.375 -0.125 -0.625

0.750 0.250 -0.250 -0.750

0.625 0.125 -0.375 -0.875

0.500 0 -0.500 -1.000];

h = num2hex(q,x)

h =

7

6

5

4

3

2

1

0

f

e

d

c

b

a

9

8

//////////////////////////////////////////////////////////////////

HEX2NUM Hexadecimal string to numeric array conversion

X = HEX2NUM(Q,H) converts hexadecimal string H to numeric matrix X.

The attributes of the number are specified by quantizer object Q.

If H is a cell array containing hexadecimal strings, then X will be

a cell array of the same dimension containing numeric matrices.

The fixed-point hexadecimal representation is two\'s complement. The

floating-point hexadecimal representation is IEEE style.

If there are fewer hex digits than are necessary to represent the

number, then fixed-point zero-pads on the left, and floating-point

zero-pads on the right.

[X1,X2,...] = HEX2NUM(Q,H1,H2,...) converts hexadecimal strings H1,

H2, ... to numeric matrices X1, X2, ....

HEX2NUM and NUM2HEX are inverses of each other, except that NUM2HEX

always returns a column.

For example, all of the 4-bit fixed-point two\'s complement numbers in

fractional form are given by:

q = quantizer([4 3]);

h = [\'7 3 F B\'

\'6 2 E A\'

\'5 1 D 9\'

\'4 0 C 8\'];

x = hex2num(q,h)

x =

0.8750 0.3750 -0.1250 -0.6250

0.7500 0.2500 -0.2500 -0.7500

0.6250 0.1250 -0.3750 -0.8750

0.5000 0 -0.5000 -1.0000

///////////////////////////////////////////////////////////////////////////////////

HEX2NUM Convert IEEE hexadecimal string to double precision number.

HEX2NUM(S), where S is a 16 character string containing

a hexadecimal number, returns the IEEE double precision

floating point number it represents. Fewer than 16

characters are padded on the right with zeros.

If S is a character array, each row is interpreted as a double

precision number.

NaNs, infinities and denorms are handled correctly.

Example:

hex2num(\'400921fb54442d18\') returns Pi.

hex2num(\'bff\') returns -1.

////////////////////////////////////////////////////////////////////

NUM2HEX Convert singles and doubles to IEEE hexadecimal strings.

If X is a single or double precision array with n elements,

NUM2HEX(X) is an n-by-8 or n-by-16 char array of the hexadecimal

floating point representation. The same representation is printed

with FORMAT HEX.

Examples:

num2hex([1 0 0.1 -pi Inf NaN]) is

3ff0000000000000

0000000000000000

3fb999999999999a

c00921fb54442d18

7ff0000000000000

fff8000000000000

num2hex(single([1 0 0.1 -pi Inf NaN])) is

3f800000

00000000

3dcccccd

c0490fdb

7f800000

ffc00000

////////////////////////////////////////////////////////////

DEC2HEX Convert decimal integer to hexadecimal string.

DEC2HEX(D) returns a 2-D string array where each row is the

hexadecimal representation of each decimal integer in D.

D must contain non-negative integers smaller than 2^52.

DEC2HEX(D,N) produces a 2-D string array where each

row contains an N digit hexadecimal number.

Example

dec2hex(2748) returns \'ABC\'.

/////////////////////////////////////////////////////////////////

HEX2DEC Convert hexadecimal string to decimal integer.

D = HEX2DEC(H) interprets the hexadecimal string H and returns in D the

equivalent decimal number.

If H is a character array or cell array of strings, each row is interpreted

as a hexadecimal string.

EXAMPLES:

hex2dec(\'12B\') and hex2dec(\'12b\') both return 299

///////////////////////////////////////////////////////////////////////////

BIN2DEC Convert binary string to decimal integer.

X = BIN2DEC(B) interprets the binary string B and returns in X the

equivalent decimal number.

If B is a character array, or a cell array of strings, each row is

interpreted as a binary string.

Embedded, significant spaces are removed. Leading spaces are converted to

zeros.

Example

bin2dec(\'010111\') returns 23

bin2dec(\'010 111\') also returns 23

bin2dec(\' 010111\') also returns 23

///////////////////////////////////////////////////////////////////////////

DEC2BIN Convert decimal integer to a binary string.

DEC2BIN(D) returns the binary representation of D as a string.

D must be a non-negative integer smaller than 2^52.

DEC2BIN(D,N) produces a binary representation with at least

N bits.

Example

dec2bin(23) returns \'10111\'

/////////////////////////////////////////////////////////////////////////