English 中文(简体)
• 1个星号! [复制]
原标题:System where 1 byte != 8 bit? [duplicate]

我现在宣读的刑期都一样。

don t rely on 1 byte being 8 bit in size

使用CHAR_BIT,而不是作为在借方和 by之间不断转换的一种方式。

et cetera. What real life systems are there today, where this holds true? (I m not sure if there are differences between C and C++ regarding this, or if it s actually language agnostic. Please retag if neccessary.)

最佳回答

On older machines, codes smaller than 8 bits were fairly common, but most of those have been dead and gone for years now.

C++已授权在8个轨道上设定一个<>最低<>m><>>>>,至少可追溯到C89标准。 [Edit: For example, C90, §5.2.4.2.1 requires CHAR_BIT >= 8 and UCHAR_ Fair >= 255. C89 use a different section number (I believe that be §2.2.4.2.1) but same content]. 它们将“果园”和“比特”视为本质上的同义词[Edit:例如,CHAR_BIT被描述为:“最小物体的比照数,不是(byte)”。

然而,在最小型号大于8倍的情况下,有现成机器(主要是DSP)——至少12、14或甚至16个轨道相当常见。 Windows CE大致相同:其最小类型(至少是微软的编辑)是16个参照点。 但是,它们将<条码>/条码>作为16条轨道处理——相反,它们采取(不改动)办法,根本不支持一个名为<条码>的类型。

问题回答

在C++世界上,依靠八分之一的加工商排在一旁是安全的。 字数不是2级(8、16、32、64)的处理器是uncommon<>。

IT WAS NOT ALWASOYS。

控制数据6600(及其兄弟)中央处理器使用了60个字眼,只能用一个字眼。 从某种意义上来说,CDC 6600 的“深造”是60个轨道。

DEC-10号分站式硬件使用任意化 by。 星号包括轨道上的星号。 我不想忘记,通过tes子可以跨越字面界限;我认为,如果星体的大小不是3、4、9或18条,就意味着你每字都有几个废物线。 (DEC-10用了36字。)

Unless you re writing code that could be useful on a DSP, you re completely entitled to assume bytes are 8 bits. All the world may not be a VAX (or an Intel), but all the world has to communicate, share data, establish common protocols, and so on. We live in the internet age built on protocols built on octets, and any C implementation where bytes are not octets is going to have a really hard time using those protocols.

It s also worth noting that both POSIX and Windows have (and mandate) 8-bit bytes. That covers 100% of interesting non-embedded machines, and these days a large portion of non-DSP embedded systems as well.

From Wikipedia:

The size of a byte was at first selected to be a multiple of existing teletypewriter codes, particularly the 6-bit codes used by the U.S. Army (Fieldata) and Navy. In 1963, to end the use of incompatible teleprinter codes by different branches of the U.S. government, ASCII, a 7-bit code, was adopted as a Federal Information Processing Standard, making 6-bit bytes commercially obsolete. In the early 1960s, AT&T introduced digital telephony first on long-distance trunk lines. These used the 8-bit µ-law encoding. This large investment promised to reduce transmission costs for 8-bit data. The use of 8-bit codes for digital telephony also caused 8-bit data "octets" to be adopted as the basic data unit of the early Internet.

As an average programmer on mainstream platforms, you do not need to worry too much about one byte not being 8 bit. However, I d still use the CHAR_BIT constant in my code and assert (or better static_assert) any locations where you rely on 8 bit bytes. That should put you on the safe side.

(I am not aware of any relevant platform where it doesn t hold true).

Firstly, the number of bits in char does not formally depend on the "system" or on "machine", even though this dependency is usually implied by common sense. The number of bits in char depends only on the implementation (i.e. on the compiler). There s no problem implementing a compiler that will have more than 8 bits in char for any "ordinary" system or machine.

Secondly, there are several embedded platforms where sizeof(char) == sizeof(short) == sizeof(int) , each having 16 bits (I don t remember the exact names of these platforms). Also, the well-known Cray machines had similar properties with all these types having 32 bits in them.

I do a lot of embedded and currently working on DSP code with CHAR_BIT of 16

In history, there s existed a bunch of odd architectures that where not using native word sizes that where multiples of 8. If you ever come across any of these today, let me know.

  • The first commerical CPU by Intel was the Intel 4004 (4-bit)
  • PDP-8 (12-bit)

The size of the byte has historically been hardware dependent and no definitive standards exist that mandate the size.

It might just be a good thing to keep in mind if your doing lots of embedded stuff.

http://en.wikipedia.org/wiki/HP_Saturn_%28microprocessor%29”rel=“nofollow”HP Saturn:

涡轮机的构造是不可磨灭的;即,核心数据单位是4个轨道,可以拥有1个双编码编码的精子。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?