How to convert character column to 4 byte (total 32 bits) data?

조회 수: 2(최근 30일)
Dohee Kim
Dohee Kim 2022년 8월 11일
답변: David Hill 2022년 8월 11일
Hi, Thank you fo much for get interest in this,
I have a numbers indicating instrument status in timetable.
For example, now it looks like this:
Time Var1
20220804 00:00:01 15226547
20220804 00:00:02 3226557
... ....
These numbers in Var1 (possibly characters, since my instrument manual saids it as 'words') should be 4 bytes and each byte has 8 bits that includes different information as 1 or 0 respectively. So in total I should have 32 digits of 1s and 0s (like binary form).
What I want to get is:
Time Var1 Bit1 Bit2 Bit3 Bit4 ... Bit 32
20220804 00:00:01 15226547 1 0 1 0 1
20220804 00:00:02 3226557 0 0 1 0 1
... .... ....
(FYI, I believe first row should be look like 00100100 according to actual instrument setup.)
I tried to change this Var1 numbers in 32digit binary form, but it seems not the correct way.
Also I tried some functions like typecast, uint32, and so on... but it is hard to figure out..
I attached Status.mat file.
Do you have any idea to solve this out?

답변(1개)

David Hill
David Hill 2022년 8월 11일
dec2bin(15226547,32)-'0'
ans = 1×32
0 0 0 0 0 0 0 0 1 1 1 0 1 0 0 0 0 1 0 1 0 1 1 0 1 0 1 1 0 0

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by