473,387 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

bits, representations in integers

Hello

Let's assume CHAR_BIT == 8, sizeof (int) == 4 and INT_MAX == 32767
(that'd mean int has 32 bits, of which only the 15 are value bits)

Now, my question is, are the value bits required to be contiguous in
the representation?
Is the position of the signed bit fixed (ie, the last bit, the first
bit)

Or even the craziest representation such as: (p = padding bits, v =
value bits, s = sign bit)

pvpvpvpv pvspvpvp pvpvpvpv pvpvpvpv

is allowed?
Oct 9 '08 #1
11 1735
vi******@gmail.com wrote:
Hello

Let's assume CHAR_BIT == 8, sizeof (int) == 4 and INT_MAX == 32767
(that'd mean int has 32 bits, of which only the 15 are value bits)

Now, my question is, are the value bits required to be contiguous in
the representation?
No. 6.2.6.1: "The representations of all types are unspecified
except as stated in this subclause," and the subclause says nothing
about how the bits are arranged.
Is the position of the signed bit fixed (ie, the last bit, the first
bit)
No.
Or even the craziest representation such as: (p = padding bits, v =
value bits, s = sign bit)

pvpvpvpv pvspvpvp pvpvpvpv pvpvpvpv

is allowed?
Sure. Note that you cannot "see" the individual bits of a byte
in isolation from the value that they represent. You might be able
to determine by experiment which byte a specified value bit occupies
(though even this much is chancy in the presence of padding bits
whose settings you do not control), but that's about all.

--
Er*********@sun.com
Oct 9 '08 #2
On Oct 9, 8:20 pm, Eric Sosman <Eric.Sos...@sun.comwrote:
Message-ID: <1223572818.225547@news1nwk>

Thanks.
Oct 9 '08 #3
Eric Sosman <Er*********@sun.comwrites:
vi******@gmail.com wrote:
>Hello

Let's assume CHAR_BIT == 8, sizeof (int) == 4 and INT_MAX == 32767
(that'd mean int has 32 bits, of which only the 15 are value bits)

Now, my question is, are the value bits required to be contiguous in
the representation?

No. 6.2.6.1: "The representations of all types are unspecified
except as stated in this subclause," and the subclause says nothing
about how the bits are arranged.
However, in some ways the compiler has to behave as if they are
contiguous. For instance, in

int a,b;
a=1;
b = a << 1;

b must be given the value 2, according to 6.5.7.
>Is the position of the signed bit fixed (ie, the last bit, the first
bit)

No.
>Or even the craziest representation such as: (p = padding bits, v =
value bits, s = sign bit)

pvpvpvpv pvspvpvp pvpvpvpv pvpvpvpv

is allowed?

Sure. Note that you cannot "see" the individual bits of a byte
in isolation from the value that they represent. You might be able
to determine by experiment which byte a specified value bit occupies
(though even this much is chancy in the presence of padding bits
whose settings you do not control), but that's about all.
Note in this case the compiler would have to implement the << and >>
operators in a rather complicated manner.
Oct 9 '08 #4
Eric Sosman <Er*********@sun.comwrites:
Nate Eldredge wrote:
>Eric Sosman <Er*********@sun.comwrites:
>>vi******@gmail.com wrote:
Hello

Let's assume CHAR_BIT == 8, sizeof (int) == 4 and INT_MAX == 32767
(that'd mean int has 32 bits, of which only the 15 are value bits)

Now, my question is, are the value bits required to be contiguous in
the representation?
No. 6.2.6.1: "The representations of all types are unspecified
except as stated in this subclause," and the subclause says nothing
about how the bits are arranged.

However, in some ways the compiler has to behave as if they are
contiguous. For instance, in

int a,b;
a=1;
b = a << 1;

b must be given the value 2, according to 6.5.7.

Yes, b is set to 2. But that's the *value* of b, a quantity
that is deduced from the representation. The representation is
described only by 6.2.6.1, which describes the meanings of various
bits of b but says nothing about how they are arranged. For example,
the 1-bit might be in the lowest-addressed byte of a while the 2-bit
is in the highest-addressed byte of b (that would be perverse, but
not forbidden).
>>>Or even the craziest representation such as: (p = padding bits, v =
value bits, s = sign bit)

pvpvpvpv pvspvpvp pvpvpvpv pvpvpvpv

is allowed?
Sure. [...]

Note in this case the compiler would have to implement the << and >>
operators in a rather complicated manner.

The << and >operators work with the values of their operands,
not with their representations. Yes, the Standard describes the
result values in terms of left and right shifts, but these are
conveniences: the Standard also describes the outcome in terms of
multiplication and division by powers of two.
Yes, we're in agreement. I just thought your post might leave the
reader with a mistaken impression. Someone could think that << and >>
actually shifted the bits of the representation (since in the common
case this is equivalent); in the crazy representation above, that would
mean 1 << 1 == 0. I wanted to clarify that this isn't the case. But
your new post is a better explanation than mine. :)
Oct 9 '08 #5
Eric Sosman wrote:
>
.... snip ...
>
Whether this notion is well-supported by the underlying machine
instructions is an issue for the machine designer and the compiler
implementor to wrangle with. The Standard does not forbid
perversity, but requires that the implementation shield the
programmer from much of it. That's good, because it gets the
Standard out of the business of trying to dictate the future of
computer design. When somebody invents the four-state memory
device and encodes two bit values in each "quit," a requirement
that each bit have its own observable existence apart from its
fellows would be an obstacle to adoption.
More interesting will be the revolution that occurs when a good
solution to implementing trinary logic is discovered. Powers of
three forever. I don't think anyone will discover a means of using
2.718281828.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Oct 10 '08 #6
CBFalconer wrote:
>
More interesting will be the revolution that occurs when a good
solution to implementing trinary logic is discovered. Powers of
three forever. I don't think anyone will discover a means of using
2.718281828.
C'mon, that's eeeeeeeeasy.

--
Eric Sosman
es*****@ieee-dot-org.invalid
Oct 10 '08 #7
In article <86************@vulcan.lanNate Eldredge <na**@vulcan.lanwrites:
Eric Sosman <Er*********@sun.comwrites:
....
No. 6.2.6.1: "The representations of all types are unspecified
except as stated in this subclause," and the subclause says nothing
about how the bits are arranged.

However, in some ways the compiler has to behave as if they are
contiguous. For instance, in

int a,b;
a=1;
b = a << 1;

b must be given the value 2, according to 6.5.7.
Yes, because the "shift" operator is not defined using shifts but using
values.
pvpvpvpv pvspvpvp pvpvpvpv pvpvpvpv

is allowed?
Sure. Note that you cannot "see" the individual bits of a byte
in isolation from the value that they represent. You might be able
to determine by experiment which byte a specified value bit occupies
(though even this much is chancy in the presence of padding bits
whose settings you do not control), but that's about all.

Note in this case the compiler would have to implement the << and >>
operators in a rather complicated manner.
Depends. If the hardware represents integers that way, why would it
not provide instructions that provide the "shift" operators?

LHS: definition: shifts the value bits of a word the number of positions.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Oct 10 '08 #8
In article <48***************@yahoo.comcb********@maineline.net writes:
....
More interesting will be the revolution that occurs when a good
solution to implementing trinary logic is discovered.
I doubt whether a good solution can be found, that is better than the
solution that actually has been used on ternary computers.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Oct 10 '08 #9
On Oct 10, 7:22*am, CBFalconer <cbfalco...@yahoo.comwrote:
More interesting will be the revolution that occurs when a good
solution to implementing trinary logic is discovered. *Powers of
three forever. *I don't think anyone will discover a means of using
2.718281828.
Obpuzzle: Describe the simple integer encoding that can
fairly be described as implementing base phi = 1.618...

James Hussein Allen
Oct 11 '08 #10


vi******@gmail.com wrote:
Hello

Let's assume CHAR_BIT == 8, sizeof (int) == 4 and INT_MAX == 32767
(that'd mean int has 32 bits, of which only the 15 are value bits)

Now, my question is, are the value bits required to be contiguous in
the representation?
Is the position of the signed bit fixed (ie, the last bit, the first
bit)

Or even the craziest representation such as: (p = padding bits, v =
value bits, s = sign bit)

pvpvpvpv pvspvpvp pvpvpvpv pvpvpvpv

is allowed?
We have created some application specific number systems
for our tools that were supported in our C compilers. Almost
all of these schemes traded dynamic range for resolution.
For example 8bit float formats with 4bits mantissa and 4 bits
exponent. 16 bit unsigned float with 5 bits exponent used in
some application.

As others pointed out most of the current hardware
is designed to process binary numbers. Non binary representations
generally have at least one group of math operators that some
implementation difficulties.

Regards,

--
Walter Banks
Byte Craft Limited
http://www.bytecraft.com

Oct 11 '08 #11
James Dow Allen wrote:
[...]
Obpuzzle: Describe the simple integer encoding that can
fairly be described as implementing base phi = 1.618...
Do you by any chance mean the A and B paper size series?

ObC: I have an experimental C compiler that, sort of, stores all values
as doubles. sizeof(char) == sizeof(int) == sizeof(double) == 1, and
sizeof(void*) == 2. And it's *completely ANSI C compatible*, subject to
bugs. There's a lot more subtlety to the location of all those pesky
'undefined behaviour' clauses in the standard than one might think at
first glance.

<plugThe compiler, Clue, at http://cluecc.sf.net, compiles C into
Javascript, Lua and Perl. I also have a C and CLisp backend in the
works... </plug>

--
┌─── dg*cowlark.com ───── http://www.cowlark.com ─────

│ ⍎'⎕',∊N⍴⊂S←'←⎕←(3=T)⋎M⋏2=T ⊃+/(V⌽"⊂M),(V⊝"M),(V,⌽V)⌽"(V,V←1⎺1)⊝" ⊂M)'
│ --- Conway's Game Of Life, in one line of APL
Oct 11 '08 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: I wish | last post by:
#include <string.h> int a; memset( a, 0, sizeof(a) ); Does that guarantee all bits zero? -- |
53
by: Zhiqiang Ye | last post by:
Hi, All I am reading FAQ of this group. I have a question about this: http://www.eskimo.com/~scs/C-faq/q7.31.html It says: " p = malloc(m * n); memset(p, 0, m * n); The zero fill is...
26
by: G Patel | last post by:
Hi, I'm wondering if anyone knows if the following function will function properly as a set-bit counter on non 2s complement machines (as K&R2 implies). | int bitcount(unsigned x) | { | ...
64
by: yossi.kreinin | last post by:
Hi! There is a system where 0x0 is a valid address, but 0xffffffff isn't. How can null pointers be treated by a compiler (besides the typical "solution" of still using 0x0 for "null")? -...
15
by: thomas.mertes | last post by:
For a hash function I want to reinterpret the bits of a float expression as unsigned long. The normal cast (unsigned long) float_expression truncates the float to an (unsigned long) integer. ...
12
by: rajm2019 | last post by:
Given two integers A & B. Determine how many bits required to convert A to B.how to write a function int BitSwapReqd(int A, int B);
11
by: Mack | last post by:
Hi all, I want to write a program to count number of bits set in a number. The condition is we should not loop through each bit to find whether its set or not. Thanks in advance, -Mukesh
77
by: borophyll | last post by:
As I read it, C99 states that a byte is an: "addressable unit of data storage large enough to hold any member of the basic character set of the execution environment" (3.6) and that a byte...
16
by: Dom Fulton | last post by:
Has anyone got a mechanism for finding the number of bits in floats, doubles, and long doubles? I need this to communicate with some hardware. I guess I could try to deduce this from float.h,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.