Thread: Binary numbers
View Single Post
Binary numbers
Old
  (#1)
Lazy
Member
 
Lazy's Avatar
 
Status: Offline
Posts: 236
Join Date: Jan 2004
Location: Toronto, Ontario, Canada
Default Binary numbers - 02-04-2004

This seems a little odd but for some reason I can only do binary operations in inline assembly blocks.

In the following example the function takes a lowercase character and XORs it with 00100000 to convert it to an uppercase character.

Code:
char charupper( char c )
{
if ( c & ( 1 << 5 ) )	 // Is bit 5 set?
{
	 __asm				 // Start inline assembly
	 {
		 mov al, c			// Move the character into the al register
		 xor al, 00100000b; // XOR the al register with 00100000 which will invert bit 5
	 }					 // End inline assembly
}
else
	 return c;			 // If the character was already uppercase, return the same character
}
That function works as expected but is limited to x86 based machines.
Is there a way to do the same thing with C?

Thanks in advance for any advice you can give.

Last edited by Lazy; 02-04-2004 at 01:06.. Reason: Bad title
  
Reply With Quote