Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have unit connected to USB. It is 4 digital input device, so I can read state of inputs by command
Code:
./arco
It returns one hexadecimal digit representing state of inputs.
My question is. How can I in most simplest way, know value of particular bit in this digit? The answer should be 0 or 1.
Any idea?
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,519
Rep:
One hex digit is 4 bits. Therefore, it cannot be represented as 0 or 1. The entire value could be 0 or 1, but it could be greater than that. If you're looking at one bit of a hex digit, usually people just memorize the bit positions.
You simply need to write your script in a programming language that knows how to do this:
Convert the hexadecimal-encoded string to its binary result.
Shift the value '1' to the left n-1 bits.
Logic-AND the two results together.
Test whether the result is or is not zero.
Although I am quite sure ... ... that some future respondent will show us how "bash scripting" can do this," I would instead recommend that you write your script in "a real programming language" (I can think of more than half-a-dozen, right off the bat) that really knows how to do this.
Then, by prefixing your script with #!language_processor_name, aka "shebang," you can use that language to "write your script."
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.