Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
SignExtend.cpp
00001 #include "mbed.h" 00002 #include "assert.h" 00003 00004 int SignExtend( int value, const int bit_width ) 00005 { 00006 assert( ( bit_width > 1) && ( bit_width < (8*sizeof(int)) ) ); 00007 00008 value &= ( (1<<(bit_width)) - 1 ); /* Clear out any extra MSB data */ 00009 00010 if ( ( value & ( 1 << (bit_width-1) ) ) != 0 ) 00011 { 00012 /* value IS negative */ 00013 value -= (1<<bit_width); 00014 } 00015 00016 return value; 00017 }
Generated on Tue Jul 12 2022 16:29:02 by
1.7.2