473,385 Members | 2,269 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,385 software developers and data experts.

8 bit integer type

typedef char int(myint8);

the above is realy what i wanna do, but ofcourse it cant be done this
way. I have looked around for a 8 bit integer type, but no luck. the
int8_t and simular still acts like chars.
Yes i know it a stupid little thing, but im getting tired of writing
int(my8bitvar); all the time, and if there is a type that doesnt act
like a char, i wanna know.

I have allso tryed defining my own type, but got lost when i had to
implement all the operator (==, -=, +=, ++, --, etc.) and besides it
seemed a really stupid way to go about it.

So please i anyone holds an answer, let me hear it.

Regards

Aug 29 '07 #1
11 21941
On 2007-08-29 11:45, za******@gmail.com wrote:
typedef char int(myint8);

the above is realy what i wanna do, but ofcourse it cant be done this
way. I have looked around for a 8 bit integer type, but no luck. the
int8_t and simular still acts like chars.
Yes i know it a stupid little thing, but im getting tired of writing
int(my8bitvar); all the time, and if there is a type that doesnt act
like a char, i wanna know.
In what way does a char differ in behaviour from an int, except for the
range of values it can hold?

--
Erik Wikström
Aug 29 '07 #2
On 29 Aug., 12:25, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-08-29 11:45, zacar...@gmail.com wrote:
typedef char int(myint8);
the above is realy what i wanna do, but ofcourse it cant be done this
way. I have looked around for a 8 bit integer type, but no luck. the
int8_t and simular still acts like chars.
Yes i know it a stupid little thing, but im getting tired of writing
int(my8bitvar); all the time, and if there is a type that doesnt act
like a char, i wanna know.

In what way does a char differ in behaviour from an int, except for the
range of values it can hold?

--
Erik Wikström
Of course it doesnt differ much, but it does differ, fx. what do you
think happened when i first head about the stdint.h and wanted to try
out the uint8-t?

@code
uint8_t var = 7;
std::cout << var;
@code

BEEP! it said.
Imagine my surprise. and integer type making funny noises?
Yes, it is a tiny little wee wee thing that nobody care about, but
still it enoys me having to write
std::cout << int(var);
Yes, it is only 5 extra letter, well that depends, but the goal of
this post was only to make certain that a real 8 bit integer type or
an easy soluton doesnt allready excist.

Aug 29 '07 #3
On 2007-08-29 12:35, za******@gmail.com wrote:
On 29 Aug., 12:25, Erik Wikström <Erik-wikst...@telia.comwrote:
>On 2007-08-29 11:45, zacar...@gmail.com wrote:
typedef char int(myint8);
the above is realy what i wanna do, but ofcourse it cant be done this
way. I have looked around for a 8 bit integer type, but no luck. the
int8_t and simular still acts like chars.
Yes i know it a stupid little thing, but im getting tired of writing
int(my8bitvar); all the time, and if there is a type that doesnt act
like a char, i wanna know.

In what way does a char differ in behaviour from an int, except for the
range of values it can hold?

--
Erik Wikström

Of course it doesnt differ much, but it does differ, fx. what do you
think happened when i first head about the stdint.h and wanted to try
out the uint8-t?

@code
uint8_t var = 7;
std::cout << var;
@code

BEEP! it said.
Imagine my surprise. and integer type making funny noises?
Yes, it is a tiny little wee wee thing that nobody care about, but
still it enoys me having to write
std::cout << int(var);
Yes, it is only 5 extra letter, well that depends, but the goal of
this post was only to make certain that a real 8 bit integer type or
an easy soluton doesnt allready excist.
Yes, I see. This is of course because uint8_t is just a typedef of an
unsigned char. I don't think anyone but the compiler vendor or library
vendor can fix this.

--
Erik Wikström
Aug 29 '07 #4
za******@gmail.com wrote:
On 29 Aug., 12:25, Erik Wikström <Erik-wikst...@telia.comwrote:
>On 2007-08-29 11:45, zacar...@gmail.com wrote:
>>typedef char int(myint8);
the above is realy what i wanna do, but ofcourse it cant be done this
way. I have looked around for a 8 bit integer type, but no luck. the
int8_t and simular still acts like chars.
Yes i know it a stupid little thing, but im getting tired of writing
int(my8bitvar); all the time, and if there is a type that doesnt act
like a char, i wanna know.
In what way does a char differ in behaviour from an int, except for the
range of values it can hold?

--
Erik Wikström

Of course it doesnt differ much, but it does differ, fx. what do you
think happened when i first head about the stdint.h and wanted to try
out the uint8-t?

@code
uint8_t var = 7;
std::cout << var;
@code

BEEP! it said.
Imagine my surprise. and integer type making funny noises?
Yes, it is a tiny little wee wee thing that nobody care about, but
still it enoys me having to write
std::cout << int(var);
Yes, it is only 5 extra letter, well that depends, but the goal of
this post was only to make certain that a real 8 bit integer type or
an easy soluton doesnt allready excist.
struct int8bit
{
unsigned int number : 8;
}

then implement a class which does everything you want to do with this.
Aug 29 '07 #5
On 29 Aug., 13:24, anon <a...@no.nowrote:
zacar...@gmail.com wrote:
On 29 Aug., 12:25, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-08-29 11:45, zacar...@gmail.com wrote:
>typedef char int(myint8);
the above is realy what i wanna do, but ofcourse it cant be done this
way. I have looked around for a 8 bit integer type, but no luck. the
int8_t and simular still acts like chars.
Yes i know it a stupid little thing, but im getting tired of writing
int(my8bitvar); all the time, and if there is a type that doesnt act
like a char, i wanna know.
In what way does a char differ in behaviour from an int, except for the
range of values it can hold?
--
Erik Wikström
Of course it doesnt differ much, but it does differ, fx. what do you
think happened when i first head about the stdint.h and wanted to try
out the uint8-t?
@code
uint8_t var = 7;
std::cout << var;
@code
BEEP! it said.
Imagine my surprise. and integer type making funny noises?
Yes, it is a tiny little wee wee thing that nobody care about, but
still it enoys me having to write
std::cout << int(var);
Yes, it is only 5 extra letter, well that depends, but the goal of
this post was only to make certain that a real 8 bit integer type or
an easy soluton doesnt allready excist.

struct int8bit
{
unsigned int number : 8;

}

then implement a class which does everything you want to do with this.- Skjul tekst i anførselstegn -

- Vis tekst i anførselstegn -
ah yes, two problems reamins however.
1. How much space does this new type use in memory? i mean is it just
an 32 bit int with an 8 bit limitation or is it infact an 8 bit int?
2. this vould not be used as a regular type but would have to be
called like int8bit.number, this is not that important, but really it
would be tha same as writing int(char), eg. more enoying code.

Aug 29 '07 #6
za******@gmail.com wrote:
On 29 Aug., 13:24, anon <a...@no.nowrote:
>zacar...@gmail.com wrote:
>>On 29 Aug., 12:25, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-08-29 11:45, zacar...@gmail.com wrote:
typedef char int(myint8);
the above is realy what i wanna do, but ofcourse it cant be done this
way. I have looked around for a 8 bit integer type, but no luck. the
int8_t and simular still acts like chars.
Yes i know it a stupid little thing, but im getting tired of writing
int(my8bitvar); all the time, and if there is a type that doesnt act
like a char, i wanna know.
In what way does a char differ in behaviour from an int, except for the
range of values it can hold?
--
Erik Wikström
Of course it doesnt differ much, but it does differ, fx. what do you
think happened when i first head about the stdint.h and wanted to try
out the uint8-t?
@code
uint8_t var = 7;
std::cout << var;
@code
BEEP! it said.
Imagine my surprise. and integer type making funny noises?
Yes, it is a tiny little wee wee thing that nobody care about, but
still it enoys me having to write
std::cout << int(var);
Yes, it is only 5 extra letter, well that depends, but the goal of
this post was only to make certain that a real 8 bit integer type or
an easy soluton doesnt allready excist.
struct int8bit
{
unsigned int number : 8;

}

then implement a class which does everything you want to do with this.- Skjul tekst i anførselstegn -

- Vis tekst i anførselstegn -

ah yes, two problems reamins however.
1. How much space does this new type use in memory? i mean is it just
an 32 bit int with an 8 bit limitation or is it infact an 8 bit int?
It would take 32 bit memory, but it would be 8-bit unsigned int.
2. this vould not be used as a regular type but would have to be
called like int8bit.number, this is not that important, but really it
would be tha same as writing int(char), eg. more enoying code.
You could encapsulate it in a class.
Aug 29 '07 #7
On 29 Aug., 14:52, anon <a...@no.nowrote:
zacar...@gmail.com wrote:
On 29 Aug., 13:24, anon <a...@no.nowrote:
zacar...@gmail.com wrote:
On 29 Aug., 12:25, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-08-29 11:45, zacar...@gmail.com wrote:
typedef char int(myint8);
the above is realy what i wanna do, but ofcourse it cant be done this
way. I have looked around for a 8 bit integer type, but no luck. the
int8_t and simular still acts like chars.
Yes i know it a stupid little thing, but im getting tired of writing
int(my8bitvar); all the time, and if there is a type that doesnt act
like a char, i wanna know.
In what way does a char differ in behaviour from an int, except for the
range of values it can hold?
--
Erik Wikström
Of course it doesnt differ much, but it does differ, fx. what do you
think happened when i first head about the stdint.h and wanted to try
out the uint8-t?
@code
uint8_t var = 7;
std::cout << var;
@code
BEEP! it said.
Imagine my surprise. and integer type making funny noises?
Yes, it is a tiny little wee wee thing that nobody care about, but
still it enoys me having to write
std::cout << int(var);
Yes, it is only 5 extra letter, well that depends, but the goal of
this post was only to make certain that a real 8 bit integer type or
an easy soluton doesnt allready excist.
struct int8bit
{
unsigned int number : 8;
}
then implement a class which does everything you want to do with this.- Skjul tekst i anførselstegn -
- Vis tekst i anførselstegn -
ah yes, two problems reamins however.
1. How much space does this new type use in memory? i mean is it just
an 32 bit int with an 8 bit limitation or is it infact an 8 bit int?

It would take 32 bit memory, but it would be 8-bit unsigned int.
2. this vould not be used as a regular type but would have to be
called like int8bit.number, this is not that important, but really it
would be tha same as writing int(char), eg. more enoying code.

You could encapsulate it in a class.- Skjul tekst i anførselstegn -

- Vis tekst i anførselstegn -
not that it matters much cause the solution is not what im looking
for, but what do you mean by "encapsulate in a class"?

Aug 29 '07 #8
za******@gmail.com wrote:
>>2. this vould not be used as a regular type but would have to be
called like int8bit.number, this is not that important, but really it
would be tha same as writing int(char), eg. more enoying code.
You could encapsulate it in a class.

not that it matters much cause the solution is not what im looking
for, but what do you mean by "encapsulate in a class"?
You can do the same for char (or unsigned char, not sure what you
using). By encapsulating it in a class, you would have to overload all
operators you are going to use (+, - , etc) and you would have to write
operator<< for that class. That way you would not have to cast when
sending to a stream.
Aug 29 '07 #9
Hi!

za******@gmail.com schrieb:
Yes, it is a tiny little wee wee thing that nobody care about, but
still it enoys me having to write
std::cout << int(var);
Yes, it is only 5 extra letter,
which can be reduced, but would also reduce the verbosity:

std::cout << +var;

The unary operator + will implicitly cast the value to int. Hard to
read, though, so it's not good for maintenance.

Frank
Aug 29 '07 #10
Wouldn't compilers still align data on word or half-word bounderies in
memory, so using a char doesn't really save any bits?

Or I could be imagining things.

--n

"Frank Birbacher" <bl************@gmx.netwrote in message
news:5j***********@mid.dfncis.de...
Hi!

za******@gmail.com schrieb:
>Yes, it is a tiny little wee wee thing that nobody care about, but
still it enoys me having to write
std::cout << int(var);
Yes, it is only 5 extra letter,

which can be reduced, but would also reduce the verbosity:

std::cout << +var;

The unary operator + will implicitly cast the value to int. Hard to
read, though, so it's not good for maintenance.

Frank

Aug 31 '07 #11
On 2007-08-31 05:59, Geoff wrote:
"Frank Birbacher" <bl************@gmx.netwrote in message
news:5j***********@mid.dfncis.de...
>Hi!

za******@gmail.com schrieb:
>>Yes, it is a tiny little wee wee thing that nobody care about, but
still it enoys me having to write
std::cout << int(var);
Yes, it is only 5 extra letter,

which can be reduced, but would also reduce the verbosity:

std::cout << +var;

The unary operator + will implicitly cast the value to int. Hard to
read, though, so it's not good for maintenance.
Please don't top-post and don't quote signatures.
Wouldn't compilers still align data on word or half-word bounderies in
memory, so using a char doesn't really save any bits?

Or I could be imagining things.
Yes you are, you are imagining that all computers work the same way,
imagine for example a computer that can align on half-word boundaries
and have a 16 bit word, that means no padding and no loss.

--
Erik Wikström
Aug 31 '07 #12

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

Similar topics

3
by: Simon G Best | last post by:
Hello! The C++ standard library provides facilities for finding out the sizes (and other such stuff) of numeric types (::std::numeric_limits<>, for example). What I would like to do is to...
28
by: Timothy Madden | last post by:
Hello I've read here that only C language has a standard 64bit integer. Can you please tell me what are the reasons for this ? What is special about C language ? Can you please show me some...
11
by: Jason Heyes | last post by:
I would like to be able to extract an integer from a stream without having to write a test when I want the integer within some range. Unfortunately there is no range-checked integer type in the...
1
by: Joe | last post by:
Hi all, I have a linux c source code that stores a float value into a type int on many occasions. Is this possible in linux or does compiler round the float value into integral type? The strange...
4
by: FatboyCanteen | last post by:
If I have a textbox, Let use to input a text. I want to check the input text is integer type or no I use isnum() to validate it, but double type also pass the validation. I don't want to use Field...
10
by: Mike S | last post by:
Does anyone know the logic behind why in VB.NET the result of a floating-point division ('/') is -rounded- on being converted to an integer type, such as with statements like Dim x As Integer =...
35
by: Frederick Gotham | last post by:
I'm writing a template, and I need to know the maximum value of a given integer type at compile time. something like: template<class NumType> class Arb { public: static NumType const max =...
3
by: veeman | last post by:
Can someone please write an example containing one element which value is integer type, and one attribute which value is also integer type: Is it something like this: <SomeAttribute...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.