View Full Version : How to isolate 10 bits from word variable?
rcbandwidth123
- 14th April 2008, 17:00
Hello All: Could someone explain how to isolate just the 10 Most significant bits from a word variable?.
Example:%1111111100000000 (16 bit word read from device)
I would like to get this:
My10Bits=%1111111100 (10 bits actual data)
I am using PicBasic-Pro 2.50
Thanks in advance
Bob C.
mat janssen
- 14th April 2008, 17:04
A word consits of a high byte and a low byte. (see manual)
There is also a shift (right) possibility in PBP. (>>)
Only you have to copy the lsb of the high byte to the msb of the low byte after every shift.
paul borgmeier
- 14th April 2008, 19:16
Also try, as suggested by Mat
My16Bits = %1111111100000000
My10Bits=My16Bits >> 6 ; lose the lower 6 bits (same as divide by 64)
rcbandwidth123
- 14th April 2008, 19:28
Thank you for your response:
The problem I'm having is joining the entire Highbyte of the Word variable with the 2 MSB's of the Lowbyte to form my 10 Bits.
I know I need to concatenate the bits together,but I am getting a bit frustrated by this...If you or anyone else can show me the coding syntax for this operation I would appreciate it.
The concatenated bits will be placed in a word variable .
Down and out :(
Bob C.
Acetronics2
- 14th April 2008, 19:47
Pfouuuuuh !!!
A is a Byte - Lower Part of THE 16bits value VAL
B is a Byte - Higher Part ....
VAL.Lowbyte = A
VAL.Highbyte = B
That'a All ...
and VAL >> 6 is What you look for.
Final point.
Alain
rcbandwidth123
- 14th April 2008, 20:10
I now understand the process!!!....ACE-I honestly RTFM but I guess I just was not understanding.
In your honor Ace I have declared RTFM as a Word variable and will use it my program :)
Again,thanks for helping me out gentleman!!
Bob C
mister_e
- 14th April 2008, 20:18
some may have learn from this RTFM expression
http://www.mister-e.org/Pics/bellow
http://www.rtfm.com/
Some also did come cofee cup
http://www.mister-e.org/Pics/cofee
:D
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.