I'm trying to create a PDU encoder which requires me to:
- Convert each char in a string into an ASCII value
- Convert the ASCII value into 7-bit binary
- Using this method - Converting 7-bit into 8 bit. I'm doing this in a function by taking the first septet, and adding from the end of the next septet until the first has 8 bits (like shown in the url). This is continued throughout basically.
- Using the 8 bit binary I can convert to Hex for my PDU string.
All this works fine when using:
ASCII = Convert.ToInt32(char)
Convert.ToString(ASCII, 2)
= 7bitSeptetToOctet(7bit)
= 8bit (My function)Convert.ToString(Convert.ToInt32(8bit, 2), 16).ToUpper()
(I'm adding a 0 if it converts to only 1 char)
Now comes my problem, when trying to convert special characters, like the danish 'ø', you get the ASCII value of 248, which with Convert.ToString(248, 2)
gives me 11111000
(8 bits). So either I need to know how to force the conversion of 'ø' to 7 bit binary, or the SeptetToOctet conversion (this the conversion on the URL provided) needs revision, but I do now have enought knowledge about binary and binary conversion to know how to get it right.