如何位的数组转换为整数,在Matlab? [英] How to convert array of bits to integer in Matlab?

查看:1003
本文介绍了如何位的数组转换为整数,在Matlab?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/1552966/converting-binary-to-decimal-without-using-loop\">Converting二进制不使用循环十进制

我在寻找最简单,最快的解决方案。我试着文档,但能找到的任何东西。

I'm looking for the simplest and fastest solution. I tried documentation but could find anything.

我有位像一个数组[0,1,1,1]我想将它转化成简单的整型数字7,我得到这个数组bitget(X,1:3),其中x是一个整数

I have an array of bits like [0, 1, 1, 1] and I want to convert it to simple int number 7. I get this array with bitget(x, 1:3), where x is an integer.

推荐答案

@埃德温的回答用途的 binvec2dec 的这是的数据采集工具箱。这toobox是一个额外的工具箱(由Mathworks公司开发的),但不是基本的MATLAB软件包的一部分。

@Edwin's answer uses binvec2dec which is part of the Data Acquisition Toolbox. This toobox is an additional toolbox (developed by Mathworks) but not part of the base MATLAB package.

下面是一个不依赖于该工具箱的解决方案。

Here is a solution that does not depend on this toolbox.


  1. 使用的 num2str 的二进制数组转换为字符串

  1. Use num2str to convert the binary array to a string

海峡= num2str(bin_vec);

str=num2str(bin_vec);

使用的 BIN2DEC 的获得十进制值

dec_num = BIN2DEC(STR);

dec_num=bin2dec(str);

这篇关于如何位的数组转换为整数,在Matlab?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆