Home
Back

Dear visitor, if you know the answer to this question, please post it. Thank you!

Note that this thread has not been updated in a long time, and its content might not be up-to-date anymore.

SJIS/JIS conversion algorithm 2008/2/8 21:18
Pleas if anyone knows i do need a sjis/jis conversion algorithm like JIS-to-SJIS one, published on http://en.wikipedia.org/wiki/Shift_JIS - i need it vice versa. thanks in advance for any help.
by iroiro  

Why don't you try iconv? 2008/2/9 10:14
If you only need to change encodings, you can try Linux iconv. If you need the pure algorithm, I really don't have a clue.
by mmedina rate this post as useful

. 2008/2/9 21:34
You should know:

- There is a gap in SJIS high byte from 0xa0 to 0xdf to avoid halfwidth katakana.
- Also a gap in SJIS low byte at 0x7f to avoid DEL.
- One SJIS "row" (0x??40 to 0x??7e and 0x??80 to 0x??fc, 188 chars)
is decomposed into two JIS "rows" (94 chars * 2).

The algorithm is as follows:

int sjis_to_jis(int sjis)
{
int sjis_high = sjis 8, sjis_low = sjis & 255;
int jis_high, jis_low;
// fill SJIS gaps
if (sjis_high = 0xe0)
sjis_high -= 0x40;
if (sjis_low = 0x80)
--sjis_low;
// "rough" conversion
jis_high = (sjis_high - 0x81) * 2 + 0x21;
jis_low = sjis_low - 0x40 + 0x21;
// fix for JIS even row
if (jis_low 0x7e) {
jis_high++;
jis_low -= 94;
}
return (jis_high 8) + jis_low;
}

where I used and because this forum does not allow
their ASCII counterparts.

This code is meant for explanation and is not very effective.
by meringue4 rate this post as useful

reply to this thread