SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
By wiggles
#118255
I'm working on a punch card dialed cellphone and I was wondering how I can handle nibbles in arduino code. The basic idea is the punch card has 10 rows with 4 columns each, the holes or lack there of are sensed with IR reflectance sensors, and the data latched into 5 PISO flip-flops. From there the arduino takes the serial stream and (this is the part I'm not sure how to do) breaks it into 10 nibbles, each being 1 digit of the phone number. Thanks for your help.
By souplogic
#118312
With not a lot of arduino specific experience - you could mod each byte by 16 to get the low order nibble and then shift 4 bits right (i think its right, the direction that makes it smaller) to leave the high order nibble.

There is probably a better way to do this - but this would work in a jam.

Also, as a faster alternative to mod, you could AND the byte with 00001111b
By stevech
#118333
vanilla C language

unsigned char b, nibble;

nibble = b & 15; // right nibble, 4 bits
nibble = b >> 4; // left nibble
By wiggles
#118515
Excellent, thanks a lot. I'll post the results when its done.