12,892,469 members (45,925 online)
Rate this:
See more:
Hello.
How we can define a new basis types?
We know hexadecimal or decimal base and conversions between these types, now how is possible to define a 256 basis type of data?
(e.g. A type for keep the ASCII values)
Thanks.
Posted 2-Jan-13 0:52am
smss IR407
Richard MacCutchan 2-Jan-13 7:50am

You already have that type: `char`.

Rate this:

## Solution 1

The 'usual way': define `256` different (ordered) symbols.
Member 8238193 2-Jan-13 7:40am

I want to do it without defining the symbols, through having the certain value.
CPallini 2-Jan-13 7:54am

You cannot have a base without thew symbols, for instance, base two has the symbols `{'0', '1'}` while base hex has `{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}`.
If you want instead have a variable type that can hold `256` different values, then, you already have it, it is the `char` (or the `unsigned char`).
Member 8238193 2-Jan-13 8:08am

Can I assuming an array for that symbols? (int array[256];//and in it save the numbers)
Member 8238193 2-Jan-13 11:51am

Doesn't have anyone an idea??
CPallini 2-Jan-13 15:49pm

Of course you can.
Rate this:

## Solution 2

In C++ there are no separate types for storing hexadecimal or decimal value. Such integral values are all stored in binary types like `int` or `unsigned int`, and to show them to the outside world you can convert them into any arbitrary number base by library functions like printf or ltoa.

There is already a basic type in C++ to store ASCII characters: `char`.

Perhaps I didn't understand your question. Please try to rephrase it.
Member 8238193 2-Jan-13 8:03am

Yes, I know these.
I trying to define 256 Basic for a software.
Consider on this e.g:
A_245 = 255
A_245 + 1 = ??
In char types, we have only an one character for holding value and if that number is larger, char type can't keep that, I need a 256 Basic System for counting 256 Basic Numbers from zero to Extreme. Is my expression illustrative?
nv3 2-Jan-13 9:10am

An unsigned char can hold values from 0 ... 255. Are you trying to construct a data type that holds 0 ... 256? Is that what you mean?
Member 8238193 2-Jan-13 10:47am

To describe what I mean, let's assume that an unsigned character have the 255 value, I want to add digit "1" and create two digits, For example in decimal basic: 9+1=10 (a digit+ a digit= two digits).
Example: in 256 basic A245 + 1 = A1_1, that A245 is a digit(255 in decimal 1,2,3,...,10,A2,A3,...,A245) and A1_1 is two digits in 256 basic = 1*255^1+1 in decimal.
I want to create a class or a structure or, anything so i can calculating the digits in 256 basic.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 OriginalGriff 270 Richard Deeming 200 Jochen Arndt 200 Vinod Jangle 160 CHill60 140
 OriginalGriff 4,942 CHill60 3,428 Jochen Arndt 2,803 Karthik Bangalore 2,456 ppolymorphe 2,115

Advertise | Privacy | Mobile
Web01 | 2.8.170424.1 | Last Updated 2 Jan 2013