stuff...

  • Increase font size
  • Default font size
  • Decrease font size
Home Software Programming
Programming

Set register bits

E-mail Print PDF

Well, we are ready to set/unset register bits. If you need to refresh your memory, you can read Meeting the Bits, Let's Shift and Bitwise Operations.


We already set a bit flag here, let's reproduce that.

Last Updated on Monday, 25 January 2010 01:29
 

Bitwise Operations

E-mail Print PDF
User Rating: / 2
PoorBest 

In previous posts I talked about what a bit is, how you can use it to represent information, and how you can extend the information quantity by combining bits. I also noted how many bits fits in a byte. In this other post, I mentioned what a shift is and how you can use it to set bit flags on micro's registers. I realized that I needed a concept before introducing to shift to unset bit flags, but the truth is that I wanted that way. So, If you think you missed the logic part of the whole thing, then reading what it follows maybe will be useful to you.

 

You are familiar with operations with numbers. You substract or add numbers by using an operation. Those numbers you use are called operands and the symbol used is called operator. So, if you add 2 and 3 and you write in our math notation (a.k.a. you are not E.T.) it's supposed to be:

 2 + 3 = 6 

There we have + as operator and number 2 and 3 as operands, and 6 being the result. The whole thing is an operation, and it's called addition. Although I didn't mentioned, operands can be an element of any kind of sets numbers: real, integer, natural, etc, and the result will depend upon that. I mean, when you add the integer 2 with a real number not integer, the result will be a real number. Well, this things do not happen with bits operations. Operands are bits and the result is another bit. Again, C bits operations are defined between bytes, so, you don't actually use a bit in those operations. But before talking about language specifics, let's present the most common bits operations.

 

Last Updated on Saturday, 14 August 2010 20:23
 

Let's shift!

E-mail Print PDF

The last article about bits was intended to people who never in his life heard the terms 'bit' and 'bytes'. You may disagree with my arragement of sheet of papers. What makes you think that 8 lockers or 8 buckets it's trully a 'byte'? They are all abstracts representations.


Nobody told you when you start learning what that lockers or buckets are. They just say to you: "This is a byte". So, you keep drawing that as a donkey following the carrot. Ok, I confess, I still using that representation. It's easy and it's fast.

Last Updated on Monday, 25 January 2010 01:29
 

Meeting the Bits

E-mail Print PDF
User Rating: / 2
PoorBest 

I like C...but no, I'm not as you may think a C-gurú for what I've stated before. I just like it. I don't like object oriented languages. Maybe the main reason resides in that I like hardware stuff (how do I get to that conclusion I don't care). The truth is that I thought that I knew C. I mean, I can read C and detecting the most used language stuff as declarations, syntax, etc. In fact, I wrote a C-- compiler in my 4th year of University. I said I like hardware. Actually, I'm an electronics hobbyist and when I inserted myself into the micocontroller world is where I knew that, I don't know C at all.

 

What the heck really means a shift? and why you are asigning 1 to an unsigned char? 1 is an integer and a char is a char! Well, those and a lot of questions arises when I get into the micro world. Note that I didn't emphatize micro as a shorthand for microcontroller. It has more meanings. Micro, as the reduced space you have while programming. Micro, as a shorthand indeed. Micro, as the variables space. When you write code for computers, be real, you don't give a sh*t about space. You need a char, you declare a char; you need an int, you declare a long; did I said double? Yes, why not? Did I mention something about being legible? Forget about that. You need space. It's all what you need, and of course, good code in the sense that it's actually doing the expected things and - if you were smart - in the most accurate way. Wanna be legible? Write a book...what? assembly code seems legible to you? Code is for coding, docs is for documenting. So, document your work. More legible you came with extra varibles, more space you waste. Please, write docs!

Last Updated on Monday, 25 January 2010 01:29
 



polls