how to define 4 bit Enumerated value and a nibble(4 bits) in Matlab

 Accepted Answer

Use a number between 0 and 15.
n = 8;
To convert to binary
nbin = dec2bin(n) - '0';
dec2bin return a string, the -'0' converts this string to an array of 0's and 1's.

5 Comments

Hi Thorsten, Is nbin the answer to a nibble or Enumerated value. I am sorry , i am really new to Programming.
It may be helpful if you provide a little more context. What do you want to do? What the purpose of the "nibble" and the "enumerated values"? What the task you have to solve?
Hi Thorsten, How to Convert String data or Timestamp data to bytes and then send those bytes to another Laptop and on the another laptop regenerate the data back to String so that it is readable to Humans. Here is my code:
TheTime = now;
dv = datevec(TheTime);
dv(6) = 0;
reconstructed_time = datenum(dv);
timediff = TheTime - reconstructed_time;
diff_secs = timediff * 24*60*60;
s = sprintf('Master node sent Sync Message at Time %s%09.6f', datestr(dv, 'yyyy-mm-dd HH:MM:'), diff_secs)
When I run it, the result is:
Master node sent Sync Message at Time 2016-02-01 13:49:51.967210
How can I convert this result to bits/Bytes and then send these bytes to another laptop via UDP. Then reconvert the Bytes to the String so that humans can read it.
Now i tried and added after this code
nbin = dec2bin(s) - '0' This gave me an array of 0s and 1s.
How to align this array into single line so that I can see it. Also how to separate and extract the first 48 bits for eg from the array.
Then how to send these bytes contained in nbin to another laptop via UDP and on another Laptop how to regenerate those Bytes into a String so that Humans can read it.
sBytes = uint8(s);
send sBytes. Reconstruct on the other side with
s = char(sBytes);
Do not bother converting to bits!!

Sign in to comment.

More Answers (0)

Categories

Tags

Asked:

PTP
on 20 Jan 2016

Commented:

on 1 Feb 2016

Community Treasure Hunt

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

Start Hunting!