卡西欧ga1100prw6000 指北针校准准。

查看: 5021|回复: 19|关注: 0
matlab怎么直接读取bin文件中的4个字节数
MATLAB 基础讨论版块优秀回答者
<h1 style="color:#3 麦片财富积分
入门, 积分 123, 距离下一级还需 377 积分
关注者: 1
我用A=fread(fid);直接读入,matlab是一个字节一个字节读入并转化为十进制,matlab可否直接从bin文件中读取4个字节数串成一个二进制数读入?
论坛优秀回答者
<h1 style="color:#3 麦片财富积分
关注者: 12
|此回复为最佳答案
它读进去是一个字节就行了,显示的十进制是咋回事取决于你的读取方式,uint8还是int8等等。
要把四个字节转化成二进制,直接dec2bin就行,但涉及到大小端的问题楼主也得考虑。
MATLAB 基础讨论版块优秀回答者
<h1 style="color:#3 麦片财富积分
关注者: 1
它读进去是一个字节就行了,显示的十进制是咋回事取决于你的读取方式,uint8还是int8等等。
要把四个字节转 ...
多谢你的解答,读进去的是一个字节,而我需要的是四个字节的二进制数,还需要进行字节的合并,对于大量数据,需要用到循环,十分耗时间,我有尝试着用A=fread(A,'float');同时读入4个字节,但得到的是浮点型数据,要怎么转化为二进制数?
MATLAB 基础讨论版块优秀回答者
<h1 style="color:#3 麦片财富积分
关注者: 1
终于将运算速率提上去了,先用A=fread(fid,'uint32');读入4个字节数的十进制数,再将十进制转化为二进制
论坛优秀回答者
<h1 style="color:#3 麦片财富积分
关注者: 12
终于将运算速率提上去了,先用A=fread(fid,'uint32');读入4个字节数的十进制数,再将十进制转化为二进制 ...
A=fread(fid,'uint32');
这么搞是按四个字节来读取的,可是没有考虑到大小端的问题。
即显示的这个无符号的整形数,是低位在前还是高位在前?而楼主需要的数据是低位在前还是高位在前?
MATLAB 基础讨论版块优秀回答者
<h1 style="color:#3 麦片财富积分
关注者: 1
A=fread(fid,'uint32');
这么搞是按四个字节来读取的,可是没有考虑到大小端的问题。
即显示的这个无符号 ...
我对大小端不熟悉,看了下原来的十六进制数是80 10 80 C0,读出来的是C0 80 10 80对应的十进制数
论坛优秀回答者
<h1 style="color:#3 麦片财富积分
关注者: 12
我对大小端不熟悉,看了下原来的十六进制数是80 10 80 C0,读出来的是C0 80 10 80对应的十进制数 ...
那如果你需要的是C0801080对应的二进制数
就应该是没问题的吧
MATLAB 基础讨论版块优秀回答者
<h1 style="color:#3 麦片财富积分
关注者: 1
那如果你需要的是C0801080对应的二进制数
就应该是没问题的吧
假如我需要的是原来的数据,我需要怎么改程序?
MATLAB 基础讨论版块优秀回答者
<h1 style="color:#3 麦片财富积分
关注者: 1
假如我需要的是原来的数据,我需要怎么改程序?
还有想请教你个问题,将m文件转化为exe可执行文件,对提高运行速率会不会有帮助??
MATLAB 基础讨论版块优秀回答者
<h1 style="color:#3 麦片财富积分
关注者: 1
那如果你需要的是C0801080对应的二进制数
就应该是没问题的吧
还有想请教你个问题,将m文件转化为exe可执行文件,对提高运行速率会不会有帮助??
站长推荐 /2
Powered by欢迎加入我们,一同切磋技术。 &
用户名: &&&
密 码: &
共有 5741 人关注过本帖
标题:请教怎么读取BIN(二进制文件)数据到数据库
等 级:新手上路
帖 子:376
结帖率:100%
&&问题点数:0&&回复次数:6&&&
请教怎么读取BIN(二进制文件)数据到数据库
1&&&2&&&3&&&4&&5&&&6&&7&&8&&9&&&a&&&b&&&c&&&d&&&e&&&f
09&&14&&13&&07&&09 12 09 12 11&&&12&&14 08&&12&&12&&23
这时bin文件的格式,一行16个字节
我的数据是这样,有个帧头判断字节,帧尾判断字节 ,一帧数据25个字节,怎么将他们保存到相关的数据库表中
附件: 您没有浏览附件的权限,请
搜索更多相关主题的帖子:
等 级:版主
威 望:170
帖 子:3896
专家分:24077
注:因为你没有提供帧的具体结构,如帧头占多少字节,帧尾又占多少,所以这个帧结构是我自己猜的,
程序代码:Option Explicit
Public Type 帧结构
&&& 帧头 As Integer
&&& 帧数据(0 To 15) As Byte
&&& 帧尾 As Long
Public Const 帧头数据 = 2816
Public Const 帧尾数据 = 51
Public Sub 打开文件(filename As String, dat() As 帧结构)
&&& Dim fj As Long
&&& Dim dattmp As 帧结构
&&& Dim i As Long
&&& Dim count As Long
&&& i = FileLen(filename)
&&& count = i / 22&&&&&&&&& '计算记录总数
&&& ReDim dat(count - 1)
&&& fj = FreeFile()
&&& '以只读固定长度的随机文件打开
&&& Open filename For Random Access Read As #fj Len = 22&&&&&&'2 + 16 + 4 每帧长度,注意本程序没有校验数据文件是否损坏
&&&&&& For i = 1 To count
&&&&&&&&Get fj, , dat(i - 1)
&&&&&&&&Next i
&&& Close fj
窗体测试代码
程序代码:Private Sub Command1_Click()
Dim 数据() As 帧结构
Call 打开文件(Text1.Text, 数据())
'下面是显示数据,没有进行数据校验
Dim i As Long
Dim j As Long
Dim k As String
Dim m As String
For i = 0 To UBound(数据)
&&& k = &&
&&& For j = 0 To 15
&&&&&&&&m = Hex(数据(i).帧数据(j))
&&&&&&&&If Len(m) = 1 Then m = &0& & m
&&&&&&&&k = k & m & & &
&&& Next j
&&& List1.AddItem k
附件: 您没有浏览附件的权限,请
授人于鱼,不如授人于渔
早已停用QQ了
等 级:新手上路
帖 子:376
等 级:新手上路
帖 子:376
bin是二进制文本文件。
以AA为开始头 中间21个字节为数据区 55为结束
将AA---55之间的数据存在ACCESS数据库
附件: 您没有浏览附件的权限,请
等 级:新手上路
帖 子:376
不需要效验和
只要判断 AA && 55 &&数据长度=23 就可以了
等 级:版主
威 望:170
帖 子:3896
专家分:24077
修改这个结构定义就行了
Public Type 帧结构
&&& 帧头 As byte
&&& 帧数据(0 To 23) As Byte
&&& 帧尾 As byte
检验时,检查帧头是不是= &HAA 和 帧尾是不是= &H55 就行了.
如果不等于,就说明本帧有错误.
这里面的 22 你按帧的长度改就是了.或者这样.
定义一个临时变量
dim tmp帧 as 帧结构
&&& count = i / len(tmp帧)&&&&&&&&&'计算记录总数
&&& '在这行后面可以加一个检验文件是否正确的方法
&&& if count * len(tmp帧)&& i then&&'文件除帧长度后不为整数,说明文件数据结构被破坏
&&&&&& msgbox &提示&
&&&&&& exit sub&&&&&&'如果不够错误,也直接读下去,那就不要这行
&&& end if
&&& Open filename For Random Access Read As #fj Len = len(tmp帧)&&&&&&'每帧长度
授人于鱼,不如授人于渔
早已停用QQ了
等 级:版主
威 望:170
帖 子:3896
专家分:24077
希望我说的你能看懂.
我现在只是读出数据来,添加到 ACCESS 数据库里.就是第二步工作了.
第一步工作把数据全读到内存了,
第二步就是把内存里的数据(结构体数组)保存到 数据库里.如果你前面会操作数据库,那么这里就简单了.我也举例了.代码有点烦琐.
授人于鱼,不如授人于渔
早已停用QQ了
版权所有,并保留所有权利。
Powered by , Processed in 0.107265 second(s), 8 queries.
Copyright&, BCCN.NET, All Rights Reserved怎么快速读取十六进制BIN文件 - Delphi当前位置:& &&&怎么快速读取十六进制BIN文件怎么快速读取十六进制BIN文件&&网友分享于:&&浏览:304次如何快速读取十六进制BIN文件?如题,如何快速读取十六进制BIN文件?对于100K以上的BIN文件,大家有没有更快的方式读取呢?------解决方案--------------------
你的文件使用的字符编码??如果是二进制文件其中数据不是字符编码,不是人可以看懂的写在memo上也没有意义啊如果不是Delphi(Pascal) code
Buf:array[0..255] of C
AssignFile(F,TempFileName);
Reset(F,1);
if IoResult=0 then begin
BlockRead(F, Buf, 256, BytesRead);
if BytesRead&0 then
Memo.Lines.Add(StrPas(Addr(Buf));
until BytesRead=0;
CloseFile(F);
12345678910
12345678910
12345678910 上一篇:下一篇:文章评论相关解决方案 12345678910 Copyright & &&版权所有&&读一个十六进制的bin文件,在bin文件添加四行头,生成新的bin文件。bin文件可以用vs打开查看。
using System.Collections.G
using ponentM
using System.D
using System.D
using System.IO;
using System.L
using System.T
using System.Threading.T
using System.Windows.F
namespace ACU_004GEN
public partial class FormMain : Form
public FormMain()
InitializeComponent();
private byte[] binC
private string vendorCode = "";
private string deviceType = "";
private string hardwareVersion = "";
private byte[] crc32 ;
private byte[] checkS
private byte[] firmwareL
private string sourceBinFile = "";
private string saveBinFile = "";
//private uint crc = 0xFFFFFFFF;
private uint crc_function = 0xEDB88320;
private uint crc32_reverse(byte[] buf)
uint crc = 0xFFFFFFFF;
//uint crc_function = 0xEDB88320;
foreach (byte bufByte in buf)
for (i = 0x01; i != 0; i &&= 1)
if ((crc & 0x) != 0)
crc &&= 1;
crc ^= crc_
else crc &&= 1;
if ((bufByte & i) != 0)
crc ^= crc_
return (crc);
private uint CheckSum(byte[] buf)
//uint crc = 0xFFFFFFFF;
uint checkSum = 0;
//uint crc_function = 0xEDB88320;
foreach (byte bufByte in buf)
checkSum = checkSum + bufB
return (checkSum);
private void Form1_Load(object sender, EventArgs e)
rbtCheckSum.Checked = true;
buttonGenerate.Enabled = false;
linkLabelBinaryName.Text = null;
private void label1_Click(object sender, EventArgs e)
private void textBox5_TextChanged(object sender, EventArgs e)
private void labelCheckSum_Click(object sender, EventArgs e)
private void buttonImportBinary_Click(object sender, EventArgs e)
//openFileDialog1 = new OpenFileDialog();
//OpenFileDialog dialog = new OpenFileDialog();
openFileDialogImport.Filter = "Binary Files (*.bin)|*.bin|All Files (*.*)|*.*";
openFileDialogImport.Title = string.Format("Open Firmware File");
openFileDialogImport.FilterIndex = 0;
openFileDialogImport.RestoreDirectory = true;
if (openFileDialogImport.ShowDialog() != DialogResult.Yes)
//sourceBinFile = openFileDialogImport.FileN
if (!File.Exists(sourceBinFile))
buttonGenerate.Enabled = true;
catch (System.Exception ex)
MessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
private void ReadWirteBinFile()
using (FileStream fs = new FileStream(saveBinFile, FileMode.Create, FileAccess.Write))
string headerRow0 = vendorCode + deviceType.Substring(0, 14);
WirteBin(fs, headerRow0, 0);
string headerRow1 = deviceType.Substring(14) + hardwareV
WirteBin(fs, headerRow1, 1);
//byte[] headerRow2 = crc32 + firmwareL
//WirteBin(fs, headerRow2, 2);
fs.Position = 16 * 2;
if (rbtCRC32.Checked == true)
fs.Write(crc32, 0, 4);
fs.Write(checkSum, 0, 4);
fs.Position = 16 * 2 + 4;
fs.Write(firmwareLength, 0, 4);
string headerRow3 = "\0";
WirteBin(fs, headerRow3, 3);
fs.Position = 4 * 16;
fs.Write(binContent, 0, binContent.Length);
}//end using
private void WirteBin(FileStream fs,string str,int row)
byte[] buffer
= System.Text.Encoding.ASCII.GetBytes(str);
fs.Position = 16 *
fs.Write(buffer, 0, str.Length);
private void buttonGenerate_Click(object sender, EventArgs e)
buttonImportBinary.Enabled = false;
vendorCode = LeftAddZero(textBoxVendorCode.Text.Trim(), 2);
deviceType = LeftAddZero(textBoxDeviceType.Text.Trim(), 18);
hardwareVersion = LeftAddZero(textBoxHardwareVersion.Text.Trim(), 4);
SaveFileDialog saveDlg = new SaveFileDialog();
saveDlg.Filter = "Binary Files (*.bin)|*.bin|All Files (*.*)|*.*";
saveDlg.Title = string.Format("Save Binary File");
saveDlg.FilterIndex = 0;
saveDlg.RestoreDirectory = true;
if (saveDlg.ShowDialog() != DialogResult.Yes)
saveBinFile = saveDlg.FileN
ReadWirteBinFile();
buttonGenerate.Enabled = false;
catch (System.Exception ex)
MessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
buttonImportBinary.Enabled = true;
buttonImportBinary.Enabled = true;
private string RightAddZero(string str, int length)
string retStr =
for (int i = str.Li&i++)
retStr = retStr + "\0";
return retS
private string LeftAddZero(string str, int length)
string retStr =
for (int i = str.L i & i++)
retStr ="\0"+ retS
return retS
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
sourceBinFile = openFileDialogImport.FileN
linkLabelBinaryName.Text = sourceBinF
binContent = File.ReadAllBytes(sourceBinFile);
firmwareLength = System.BitConverter.GetBytes(binContent.Length);
//Array.Reverse(firmwareLength);
textBoxFileLength.Text = LeftAddZero(binContent.Length.ToString("X8"), 8);
uint crcTmp = crc32_reverse(binContent);
crc32 = System.BitConverter.GetBytes(crcTmp);
uint checkSumTmp = CheckSum(binContent);
checkSum = System.BitConverter.GetBytes(checkSumTmp);
//Array.Reverse(crc32);
textBoxCRC32.Text = LeftAddZero(crcTmp.ToString("X8"), 8);
textBoxCheckSum.Text = LeftAddZero(checkSumTmp.ToString("X8"), 8);
阅读(...) 评论()}

我要回帖

更多关于 卡西欧ga1100调表视频 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信