Skip to content

Instantly share code, notes, and snippets.

@takamame0205
Last active January 20, 2019 16:39
Show Gist options
  • Save takamame0205/4ec7c83fddcb5ee76b4df18bd4df6926 to your computer and use it in GitHub Desktop.
Save takamame0205/4ec7c83fddcb5ee76b4df18bd4df6926 to your computer and use it in GitHub Desktop.
uint16_t sjis2jis( uint16_t charcode )
{
// シフトJISコードをJISコードに変換する
// charcode = シフトJISコード
// 戻り値:JISコード
uint8_t h, l;
h = charcode >> 8;
l = charcode & 0xff;
if ( h >= 0xe0 ) {
h -= 0x40;
}
if ( l >= 0x80 ) {
l--;
}
if ( l >= 0x9e ) {
h = ( h - 0x70 ) << 1;
l -= 0x7d;
}
else {
h = ( ( h - 0x70 ) << 1 ) - 1;
l -= 0x1f;
}
return h << 8 | l;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment