06-12-2020 11:14 PM
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'.
06-12-2020 11:23 PM
The smallest number you can represent on a computer is one byte, so you're stuck with it.
06-12-2020 11:24 PM
This is an unusual request. Tell us the reason why; I have a feeling you don't have to do this.
06-13-2020 12:35 AM - edited 06-13-2020 10:51 AM
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.
06-13-2020 03:31 AM
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.
06-13-2020
03:33 AM
- last edited on
06-13-2020
01:50 PM
by
altenbach
@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?
06-13-2020 07:40 AM
And if Life give you an unsigned Byte, here's how to get two Nibbles (hey, I just got the pun ...):
Bob Schor
06-13-2020 10:42 AM
@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:
06-13-2020 11:15 AM
@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.
(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)
06-14-2020 12:43 AM
@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:
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. 😄