LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to save Nibbles (4bit-pieces)?

Hi,
I have a Hex String which I would like to write to file. Each hex
charakter should be represented by a nibble.
I convert the hex characters to decimal characters, then I use
"decimal string to numbers" vi and change the format to U8.
The problem is, if I look at the written file with a hex-editor, each
nibble is filled up to 8 bit with zeros.
For example if I save a few hex characters "03F01042" to file and open
it with the hex-editor it would look like "00030F0001000402" (each
character added a prefix-zero).
I thought I would have to write to file with nibbles not with U8 but I
didn't found any vi that could do so.
Anybody an idea how to overcome this little problem?
Thanks in advance.
0 Kudos
Message 1 of 5
(5,059 Views)
Hi Toni,

An easy solution would be to write 2 hex characters at the time to the file...

Benoit
0 Kudos
Message 2 of 5
(5,059 Views)
I just solved a similar problem the hard way.

There was an instrument which communicated over serial (visa), and I wanted
to deal with the nibbles. I did:

- string to U8 byte array
- indexed the byte array for each U8
- converted U8 to boolean array
- get desired nibble as a subset of the boolean array
- build-array (concatenate inputs) with each high and low nibble
- build an array of U8
- convert U8 array to string

Something like that should work for you..... If you need any help email me
at joey@quantumsignal.com

-joey

"Toni Lindner" wrote in message
news:998e6cbb.0208090532.61174ed7@posting.google.com...
> Hi,
> I have a Hex String which I would like to write to file. Each hex
> charakter should be represented by a nibble.
> I conv
ert the hex characters to decimal characters, then I use
> "decimal string to numbers" vi and change the format to U8.
> The problem is, if I look at the written file with a hex-editor, each
> nibble is filled up to 8 bit with zeros.
> For example if I save a few hex characters "03F01042" to file and open
> it with the hex-editor it would look like "00030F0001000402" (each
> character added a prefix-zero).
> I thought I would have to write to file with nibbles not with U8 but I
> didn't found any vi that could do so.
> Anybody an idea how to overcome this little problem?
> Thanks in advance.
0 Kudos
Message 3 of 5
(5,059 Views)
Thanks BigBen and Joey for your help.
I did it the hard way as Joey described and tried to post this little vi called "Hex_save" to the community.
Toni
0 Kudos
Message 4 of 5
(5,059 Views)
Hi All,

There is a more efficient way to build an U8 out of 2 nibbles in U8's and that
is to use the Logical Shift functions in the 'Advanced\Data Manipulation'
Palette.
Instead of explaining, how to do it, I have attached an example VI.

Tim


Joey Oravec wrote:

> I just solved a similar problem the hard way.
>
> There was an instrument which communicated over serial (visa), and I wanted
> to deal with the nibbles. I did:
>
> - string to U8 byte array
> - indexed the byte array for each U8
> - converted U8 to boolean array
> - get desired nibble as a subset of the boolean array
> - build-array (concatenate inputs) with each high and low nibble
> - build an array of U8
> - convert U8 array to string
>
> Something like that should work for you..... If y
ou need any help email me
> at joey@quantumsignal.com
>
> -joey
>
> "Toni Lindner" wrote in message
> news:998e6cbb.0208090532.61174ed7@posting.google.com...
> > Hi,
> > I have a Hex String which I would like to write to file. Each hex
> > charakter should be represented by a nibble.
> > I convert the hex characters to decimal characters, then I use
> > "decimal string to numbers" vi and change the format to U8.
> > The problem is, if I look at the written file with a hex-editor, each
> > nibble is filled up to 8 bit with zeros.
> > For example if I save a few hex characters "03F01042" to file and open
> > it with the hex-editor it would look like "00030F0001000402" (each
> > character added a prefix-zero).
> > I thought I would have to write to file with nibbles not with U8 but I
> > didn't found any vi that could do so.
> > Anybody an idea how to overcome this little problem?
> > Thanks in advance.
0 Kudos
Message 5 of 5
(5,059 Views)