Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'encoding': 0.05; 'subsequent': 0.05; 'utf-8': 0.07; 'bits': 0.09; 'indicates': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:few': 0.09; '110': 0.16; '8-bit': 0.16; '????????': 0.16; 'directive': 0.16; 'encodes': 0.16; 'encodings': 0.16; 'message-id:@4ax.com': 0.16; 'octets': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'sequence,': 0.16; 'sequence.': 0.16; 'utf8': 0.16; 'wed,': 0.18; 'bit': 0.19; 'starts': 0.20; '>>>': 0.22; '+0000': 0.22; 'byte': 0.24; 'bytes': 0.24; 'specify': 0.24; 'tells': 0.24; 'unicode': 0.24; 'url:home': 0.24; 'initial': 0.24; 'second': 0.26; 'values': 0.27; 'header:X -Complaints-To:1': 0.27; 'rest': 0.29; 'character': 0.29; 'specified': 0.30; 'url:wiki': 0.31; 'url:wikipedia': 0.31; 'supposed': 0.32; 'point.': 0.35; 'but': 0.35; 'sequence': 0.36; 'set.': 0.36; 'entry': 0.36; 'url:org': 0.36; 'two': 0.37; 'being': 0.38; 'received:76': 0.38; 'to:addr:python-list': 0.38; 'anything': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'how': 0.40; 'signal': 0.60; 'length': 0.61; 'first': 0.61; 'inherent': 0.84; 'total,': 0.84; 'valid)': 0.84; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: A few questiosn about encoding Date: Thu, 13 Jun 2013 18:46:12 -0400 Organization: IISS Elusive Unicorn References: <6dfa3707-80f4-407a-a109-66dbb0130513@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: adsl-76-249-19-184.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 54 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1371163584 news.xs4all.nl 15879 [2001:888:2000:d::a6]:40586 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:48038 On Wed, 12 Jun 2013 09:09:05 +0000 (UTC), ???????? ?????? declaimed the following: >>> (*) infact UTF8 also indicates the end of each character > >> Up to a point. The initial byte encodes the length and the top few >> bits, but the subsequent octets aren’t distinguishable as final in >> isolation. 0x80-0xBF can all be either medial or final. > > >So, the first high-bits are a directive that UTF-8 uses to know how many >bytes each character is being represented as. > >0-127 codepoints(characters) use 1 bit to signify they need 1 bit for >storage and the rest 7 bits to actually store the character ? > Not quite... The leading bit is a 0 -> which means 0..127 are sent as-is, no manipulation. >while > >128-256 codepoints(characters) use 2 bit to signify they need 2 bits for >storage and the rest 14 bits to actually store the character ? > 128..255 -- in what encoding? These all have the leading bit with a value of 1. In 8-bit encodings (ISO-Latin-1) the meaning of those values is inherent in the specified encoding and they are sent as-is. BUT, in UTF-8, a byte with a leading 1-bit signals that the byte identifies a multi-byte sequence. CF: https://en.wikipedia.org/wiki/UTF-8#Description So anything that starts with bits 110 is a two byte sequence (and the second byte must start with bits 10 to be valid) 1110 starts a three byte sequence, 11110 starts a four byte sequence... Basically, count the number of leading 1-bits before a 0 bit, and that tells you how many bytes are in the multi-byte sequence -- and all bytes that start with 10 are supposed to be the continuations of a multibyte set (and not a signal that this is a 1-byte entry -- those only have a leading 0) >Isn't 14 bits way to many to store a character ? Original UTF-8 allowed for 31-bits to specify a character in the Unicode set. It used 6 bytes -- 48 bits total, but 7 bits of the first byte were the flag (6 leading 1 bits and a 0 bit), and two bits (leading 10) of each continuation. -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/