十进制转换为二进制为双类型的数组,不串 [英] Decimal to binary as double type array, not string

查看:191
本文介绍了十进制转换为二进制为双类型的数组,不串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个至今:

data = 14
out = dec2bin(data, 4)

这给:

out = 1110

不过,我想在这种格式的二进制数:

But I want to get binary number in this format:

out = [1 1 1 0]

感谢您的帮助!

推荐答案

您正在寻找的 de2bi '左MSB选项。

You're looking for de2bi with the 'left-msb' option.

data = 14
out = de2bi(data, 4,'left-msb')

这就要求通讯系统工具箱虽然。或者用你原来的做法与基本 DEC2BIN 具有以下附加:

Which requires the Communication Systems Toolbox though. Alternatively use your original approach with the fundamental dec2bin with the following addition:

data = 14
out = double( dec2bin(data, 4) ) - 48


out =

     1     1     1     0

这篇关于十进制转换为二进制为双类型的数组,不串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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