Steven Goossens
Steven Goossens

Reputation: 55

convert ÿ character to single byte 0xFF python

I'm trying to read a file and send the data to a socket. But I can't convert a ÿ character to a single byte.

Not if I read a file or use a string and convert it. I think the problem is the coding of the file but I can't seem to find the correct one. For this example I will only show the string conversion.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import binascii

s = "ÿ"
b = bytearray(s)
print binascii.hexlify(b)

>>result: c3bf

so the ÿ character is stored as 2 bytes. But I want to convert it to a single bytes that's 0xFF.

thanks in advance

Upvotes: 0

Views: 1784

Answers (1)

wanjijul
wanjijul

Reputation: 252

Try this:

s.decode("utf-8")

Output:

Reults

Upvotes: 3

Related Questions