这是LabVIEW NXG系列的第三篇文章,我们将介绍简单的数据类型以及它们之间的简单转换。
![](https://habrastorage.org/webt/dy/nb/fs/dynbfs1fxqsix-mq0xplhsaq-jc.png)
LabVIEW类型系统与“经典”编程语言非常相似。在本文中,我们将考虑基本类型-数值型,布尔型和字符串(尽管形式上字符串不属于简单的标量类型)。
理解类型系统的最简单方法是制作一个带有不同类型的控件和指示器的小工具:
![](https://habrastorage.org/webt/ea/oz/_u/eaoz_ufoijkikiu-tegf6ds2e6s.png)
并将它们连接到图上,如下所示:
![](https://habrastorage.org/webt/gn/kq/ni/gnkqnijtzit1xedyhpc2yx79iac.png)
, " In" " Out". LabVIEW, , ( ).
— , 8, 16, 32 64 , ( 4 8 ), — . :
![](https://habrastorage.org/webt/id/su/kr/idsukrkvyiqj_rz6gltpis8jsws.png)
:
![](https://habrastorage.org/webt/iv/om/xw/ivomxwc9aqezh2ecyxcvxf2a1ea.png)
( , ). , ? :
![](https://habrastorage.org/webt/qp/v-/yh/qpv-yhtdbyabvehms8bxug2e6au.png)
"" ( Coercion Dots), , .
SGL DBL , , U8 I32, , DBL->SGL, DBL->I32 I32->U8 , :
![](https://habrastorage.org/webt/ni/ho/kl/nihoklkcm1ufw0jynufhujuhjro.png)
"" LabVIEW Coercion Dots , :
![](https://habrastorage.org/webt/ho/bz/lp/hobzlpfctludklwxtjd07q0ybni.png)
, ? , Data Types->Numeric->Conversion:
![](https://habrastorage.org/webt/3b/hx/6h/3bhx6hegzazrlnfspydqwhzvnzg.png)
:
![](https://habrastorage.org/webt/d9/no/ia/d9noiav1iifrssa9kcr0bkz1b-i.png)
Coercion Dot, .
![](https://habrastorage.org/webt/1k/i1/r7/1ki1r74juadbcs64udkmlbpjt7i.png)
, , , DBL, :
![](https://habrastorage.org/webt/ev/n2/ph/evn2ph1m0uboyznddkgwulaxibm.png)
, , ( LabVIEW Compound Arithmetic):
![](https://habrastorage.org/webt/a5/nw/bz/a5nwbzq91s3igfojzm-y70_z_ay.png)
LabVIEW . , :
double res;
res = 5/3;
Console.WriteLine(res);
"1".
LabVIEW , 1,66 (1,66666666666667 ):
![](https://habrastorage.org/webt/wr/6p/c-/wr6pc-1zsxtnanz_iedn01z-tv8.png)
, LabVIEW , , , C# ( "" ).
, , :
![](https://habrastorage.org/webt/xw/1g/fv/xw1gfvviu8ex2bv2a2tm5erxpbk.png)
, . , , , :
![](https://habrastorage.org/webt/7o/il/yu/7oilyurbffdtqx-fj_0_vdpjhxc.png)
C# ( , int, , :
static void Main(string[] args)
{
byte x_U8 = 200, y_U8 = 200, res_U8;
res_U8 = x_U8 + y_U8;
Console.WriteLine(res_U8);
}
:
res_U8 = (byte)(x_U8 + y_U8);
, LabVIEW, , LabVIEW , , ( ):
![](https://habrastorage.org/webt/zo/gs/vr/zogsvryi6frz08tk4es4cfuiql4.png)
, , :
![](https://habrastorage.org/webt/qo/8d/4h/qo8d4h4afa288qchuezzhex-ewa.png)
LabVIEW ( "" ) — .
LabVIEW C# Microsoft, :
class Program
{
static void Main(string[] args)
{
Console.WriteLine(5.0/0.0);
}
}
"8". , , "", "Infinity", . , .NET Core — , ( , , " " Windows 10 2004). , , , , , , , .
, , LabVIEW:
![](https://habrastorage.org/webt/up/si/gq/upsigq71mdcgjs6ztyih6fj-lsk.png)
— . :
![](https://habrastorage.org/webt/p6/5a/im/p65aima-iy90rm8f5a-yoawgazm.png)
, NaN (Not a Number):
![](https://habrastorage.org/webt/tm/je/gk/tmjegk8pliyzqsvpfbft75avo6m.png)
NaN Not a Number? :
![](https://habrastorage.org/webt/x6/iz/qp/x6izqp_lk6zdnpbdezfpq35w274.png)
— .
.
# :
static void Main(string[] args)
{
Console.WriteLine(5/0);
}
...
static void Main(string[] args)
{
int zero = 0;
Console.WriteLine(5/zero);
}
… System.DivideByZeroException, LabVIEW — , .
![](https://habrastorage.org/webt/wz/wn/ie/wzwnie9l2dy0ltj0-mudajec8jg.png)
() :
![](https://habrastorage.org/webt/xu/in/ob/xuinobtpd2n5zd7akkm7lvjumu8.png)
Conversions :
![](https://habrastorage.org/webt/q0/fx/ho/q0fxholvjlukfxyozra9w_k38by.png)
:
![](https://habrastorage.org/webt/ox/b0/cf/oxb0cfwu5daa9joxz3lwnyrgkes.png)
, , :
![](https://habrastorage.org/webt/di/cy/to/dicytorhysnuqomqkcs_5rqhuia.png)
:
![](https://habrastorage.org/webt/88/pg/4b/88pg4bw2dkeuxghuk98khw2icro.png)
, , :
static void Main(string[] args)
{
string hello = "Hello, ";
string habr = "Habr!";
Console.WriteLine(hello + habr);
}
LabVIEW " " , :
![](https://habrastorage.org/webt/cw/gz/ay/cwgzaytfecjrfq7tmmsojufscsk.png)
. , Boolean to Integer :
![](https://habrastorage.org/webt/vk/zi/v7/vkziv7f8gcrzvfgjyjjomri03yc.png)
LabVIEW. False:
![](https://habrastorage.org/webt/ep/60/tn/ep60tnfa7wm8yemblh4vzrabs_o.png)
, :
![](https://habrastorage.org/webt/ud/p0/j1/udp0j1qxb_gh4-x4exmtriivvbg.png)
Type Cast
"Type Cast", . :
![](https://habrastorage.org/webt/ou/fw/uo/oufwuosg2zylhn-yjk9udklkzdw.png)
"Type", . "by flattening it and unflattening". "/".
, SGL I32:
![](https://habrastorage.org/webt/yx/oa/co/yxoacon7vvmkfryzogiv04w6260.png)
output? "1040187392". ?
:
![](https://habrastorage.org/webt/pt/91/si/pt91sius0cpjkg66vfbt_bhtixo.png)
这是0x3E000000。发生以下情况-浮点数的四个字节被重新解释为四个字节的整数。我故意采用数字0.125,因为如果您按照IEEE754查看0.125,则将看到尾数集只有5位-这在高字节中为我们提供了3E值。
在撰写了三篇文章之后,我们应该相当自信地处理三种类型的数据:
![](https://habrastorage.org/webt/al/cb/2o/alcb2ocslxgwnyzefx6zb_wctom.png)
如果您对所展示的材料有任何疑问,请在评论中提问,在下一篇文章中,我们将考虑阵列。