LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Nibble to Hex

Hi,

I wanted to convert a nibble to hex. Like eg. the hex representation of 12 in LabVIEW is 0C. I just want nibble hex conversion. Like 12 should give me output as 'C' and not '0C'.

0 Kudos
Message 1 of 10
(2,626 Views)

The smallest number you can represent on a computer is one byte, so you're stuck with it.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 10
(2,616 Views)

This is an unusual request.  Tell us the reason why; I have a feeling you don't have to do this.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 3 of 10
(2,613 Views)

Limit your integer to 4bits and set the display format to %x.

 

You are not talking about datatypes, so if the input is a decimal string containing numbers 0..9, and the number is less than 0 through 15 and you want to convert it to a string containing two characters in the range 0 through F, that would be equally easy. 

Message 4 of 10
(2,592 Views)

You can use an 8-bit enum and populate items 0-15 (even if the names are just "0" through "15") to make it pretty idiot-proof to enter invalid values.  Then it's just a matter of changing it into an array of Booleans and take the first four elements.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 5 of 10
(2,557 Views)

@altenbach wrote:

Limit your integer to 4bits and set the display format to %x.

 

You are not talking about datatypes, so if the input is a decimal string containing numbers 0..9, and the number is less than 0 through 15 and you want to convert it to a string containing two characters in the range 0 through F, that would be equally easy. 


Oh, I didn't think to interpret it this way.  Thanks for catching that.  But how do you limit your integer to 4 bits?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 10
(2,555 Views)

And if Life give you an unsigned Byte, here's how to get two Nibbles (hey, I just got the pun ...):

Nibbles.png

Bob Schor

 

Message 7 of 10
(2,524 Views)

@billko wrote:
But how do you limit your integer to 4 bits?

If it is an integer control, you can play with the "data entry" feature and restrict the allowed range. If the value comes from wlsewhere you need to decide what to do if the value is out of range (pop an error, ignore the extra bits, etc.)

 

Here's how you could blank all extra bits:

 

altenbach_1-1592062951553.png

 

 

 

0 Kudos
Message 8 of 10
(2,516 Views)

@manas0911 wrote:

I just want nibble hex conversion. Like 12 should give me output as 'C' and not '0C'.


Don't confuse "conversion" with display "formatting". The only reason to always see "0C" instead of "C" is if this is a string set to hex display. If you use any plain string or numeric you can freely format it as anything you want.

 

altenbach_0-1592064811537.png

(Note that the mask guarantees that the value is limited to a single hex character and is not needed if the input is guaranteed to be limited to a nibble)

 

0 Kudos
Message 9 of 10
(2,508 Views)

@altenbach wrote:

@billko wrote:
But how do you limit your integer to 4 bits?

If it is an integer control, you can play with the "data entry" feature and restrict the allowed range. If the value comes from wlsewhere you need to decide what to do if the value is out of range (pop an error, ignore the extra bits, etc.)

 

Here's how you could blank all extra bits:

 

altenbach_1-1592062951553.png

 

 

 


Oh, I thought there was some kind of magic involved.  I see you were actually talking about how to limit an 8-bit number to "care" about just the lower nibble.  😄

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 10 of 10
(2,480 Views)