76 % 10 gives you six
76 / 10 gives you seven assuming the 76 is in an int
This works fine down to 11
Wrong. It works for all numbers between 0 and 99 inclusive.
ian332isport:
ad2049q:
Look up what 76&15 would do, also (76&240)>>4
Or try it.
76&15 appears to give 12
(76&240)>>4 appears to give 4
I think the person answering thought you meant base 16 (hex) and not base 10 (decimal). Actually, you asked about extracting nibbles, so this is the right answer.
-76 was an example. This value can be anywhere between -96 and +3dB (representing decimal values from 0 to 198).
So the term nibble was incorrect. 76 decimal has an upper nibble of 4 decimal and a lower nibble of 12 decimal, not 7 and 6 respectively like you stated.
-10 would require:
byte name [11] = 0x31 (0x31 is ASCii 1)
byte name [12] = 0x30 (0x30 is ASCii 0)
I think you're using the wrong terminology. You're not trying to extract nibbles, you're trying to convert a number into its ASCII representation.
AWOL:
You've got a problem if your values are signed.
I'd first check the sign bit, then take the absolute value of the byte.
Yep, I can never remember if the C modulus rounds to zero or negative infinity. On a positive dividend it makes no difference but with a negative dividend they give different results. You also have to know if the sign of the result is the dividend's or the divisor's. Certain C standards do not specify which.
ad2049q:
Look up what 76&15 would do, also (76&240)>>4
Or try it.
76&15 appears to give 12
(76&240)>>4 appears to give 4
Which is the lower and upper nibbles of 76 decimal, like your original question asked for.
Maybe I've got the terminology wrong.
From 76, I want to split it apart and have a 7 and a 6.
I want to send the number 76 (as an example) over a data bus. It sends each character as HEX bytes equivalent to ASCII characters. To send the 7 I need to send 0x37, and to send the 6 I need to send 0x36. I can't send 76 as one byte, as 76 gives 0x4C which is the letter L.
ian332isport:
It sends each character as HEX bytes...
A hex byte? A byte is eight bits and hex is a number base. So, a hex byte is the same as a decimal byte which is the same as an octal byte which is the same as a sexagesimal byte which is the same as .....
I'm really confused to be honest. Are you not just sending bytes or maybe it's binary coded decimal where a number is two nibbles and each nibble is of course a hex digit.
ian332isport:
Maybe I've got the terminology wrong.
From 76, I want to split it apart and have a 7 and a 6.
I want to send the number 76 (as an example) over a data bus. It sends each character as HEX bytes equivalent to ASCII characters. To send the 7 I need to send 0x37, and to send the 6 I need to send 0x36. I can't send 76 as one byte, as 76 gives 0x4C which is the letter L.
Ian.
You see the two bytes (represented as HEX) in red. I need to replace those bytes with 0x37 and 0x36 (assuming int a =76 - it varies with the volume level). I can't send the 76 in HEX (4C), as this represents the ASCII letter L. I need to send the 7 and the 6 as separate bytes in HEX.
I'm afraid I can't think of any other way to explain this.