Extracting value from a hex number

retepsnikrep

Senior Member
I have a variable hex number in a Picaxe byte variable. In this example lets assume it is $14

How can I extract the value of the right hand digit i.e. 4 into another byte variable? Masking?
 

Dippy

Moderator
Several ways, do remember that with hex that the left digit and right digit tie up with left and right 4 bits of the byte ... now you can do it yourself eh?
 

westaust55

Moderator
and if you want just the left digit (each 4 bits is called a nybble or nibble)

answer = $14 / 16 = $01

The divide by 16 shifts the value 4 bits to the right and fills the left nybble with zeros.
 

Dippy

Moderator
or bitwise or >> ... or, in other places, an alias - so many ways to skin a cat eh?
But, best to work it out yourself rather than spoonfeed huh?
 

westaust55

Moderator
true.

Reason I did not mention >>
is trying to keep things more universal
and the >> is only available for X1 and X2 parts
 
Top