The next tutorial covering some basic data types and in introduction into variables using the C programming language is now available. Make sure to watch the 1080p version if your connection allows it:
Due to time restrictions, all of the promised future C tutorials will be in video format. Here’s the video reworking of my previous written “Hello, World!” tutorial (make sure to watch it in 1080p if you can):
I hope you learned something, and if you have any comments or questions, please let me know by posting a comment below.
Operations Table
| Operation | Sample | C Operator |
|---|---|---|
| AND | 1001 AND 0101 = 0001 |
& (ampersand) |
| OR | 1001 OR 0101 = 1101 |
| (pipe) |
| NOT | NOT 1001 = 0110 |
~ (tilde) |
| XOR | 1001 XOR 1011 = 0010 |
^ (caret) |
| LEFT-SHIFT | LEFT-SHIFT 0001 BY 1 = 0010LEFT-SHIFT 0001 BY 3 = 1000 |
<< |
| RIGHT-SHIFT | RIGHT-SHIFT 1000 BY 1 = 0100RIGHT-SHIFT 1000 BY 3 = 0001 |
>> |
C Assignment Operators
| Operation | Syntax | Short For |
|---|---|---|
| AND | X &= Y; |
X = X & Y; |
| OR | X |= Y; |
X = X | Y; |
| XOR | X ^= Y; |
X = X ^ Y; |
| LEFT-SHIFT | X <<= Y; |
X = X << Y; |
| RIGHT-SHIFT | X >>= Y; |
X = X >> Y; |
Setting & Checking Bit-Flags:
#include <stdlib.h>
#define FLAG_ONE 0x0001 /* 0001 */
#define FLAG_TWO 0x0002 /* 0010 */
#define FLAG_THREE 0x0004 /* 0100 */
int main(void)
{
unsigned int Flags = 0x0000; /* Initialize to zero */
Flags |= FLAG_ONE; /* Flags now contains 0001 */
Flags |= FLAG_THREE; /* Flags now contains 0101 */
/* will return EXIT_SUCCESS since we never set FLAG_TWO: */
return (Flags & FLAG_TWO) ? EXIT_FAILURE : EXIT_SUCCESS;
}
Counting Set Bits:
#include <stdlib.h>
#include <stdio.h>
#define BITS_PER_INT ( sizeof(unsigned int) * 8 )
int main(void)
{
unsigned int Flags = 0x0115; /* Dec: 277, Bin: 100010101 */
unsigned int Mask = 0x0001;
unsigned int Count = 0;
unsigned int i = 0;
for (i = 0; i < BITS_PER_INT; ++i, Mask <<= 1)
if (Flags & Mask)
++Count;
// The following line should print: Flags contains 4 set bits.
printf("Flags contains %d set bits.\n", Count);
return EXIT_SUCCESS;
}
If you work in a source controlled environment, these are the minimal guidelines that you’ll have to stick to for making your teammates’ lives a bit easier.
- Don’t Check-In Broken Code: More than often, you’ll pull down the latest version of a project from your repository only to find that the code won’t build. Please, don’t check-in code to the main project that doesn’t compile, even if you intend to pick up the slack the next day. However:
- Don’t Go Home Without a Check-In: Even though you shouldn’t check-in your broken code to the main branch, many source control systems have a way to branch a user’s changes and merge them back later. If you’re using Team Foundation Server, take a look at Shelve Sets.
- Use Check-In Comments: Always leave a descriptive comment of the work you’ve done when your check-in. Your teammates weren’t hired to analyze undocumented code, so that 500-line change across multiple files better have a comment.
- Check-In Association: If your source control system allows this type of integration, associate your check-in with a work item, bug, or help-desk ticket. If it does not, at least make a reference to the work item’s identifier in the comment section.
- Use Check-In Policies: Use check-in policies to ensure that all of the above things aren’t impeding your build if your source control system supports them. These policies make your life easier and disallow sneaky developers from checking-in their broken spaghetti code.
Share any tips you may have!
If you ask a programmer which programming language you should learn as your first, they’ll often prescribe you their personal favorite, often not considering if the language is supported on multiple platforms, easy to learn, exposing underlying system mechanics, and fully featured.
This post is the first of a series of tutorials intended to teach you the C programming language, an excellent first language because of the following reasons:
- Supported on all major operating systems
- Relatively straight-forward syntax
- Mature and stable feature set
- Used in many articles, books, and other publications
- Easy transition into higher-level languages
Microsoft confirmed today at the 2011 CES that the next generation of the Windows operating system will indeed run on ARM processors, following wild rumors and speculation this past week.
Windows on ARM processors means that the operating system is now capable of running on a plethora of mobile devices, thus opening up an entirely new market segment for Microsoft. Is this the end of Windows Phone? Will Windows 8 be the new Microsoft mobile OS?
EDIT (01/06): Not much more info was released in last night’s keynote speech by Steve Ballmer. However, the implications of having the full-fledged Windows operating system on a mobile device such as a phone are tremendous. Android and iOS will have to pick up some speed to compete with the OS that has been in the making since 1985 and has excellent hardware and software support e.g.: multi-threading, scheduling, peripheral support, .NET Framework, WPF, Win32 API, etc., etc.
Scriptionary 