Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Comments
Richard MacCutchan 2-Jan-13 7:50am    
You already have that type: char.

The 'usual way': define 256 different (ordered) symbols.
 
Share this answer
 
Comments
smss IR 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).
smss IR 2-Jan-13 8:08am    
Can I assuming an array for that symbols? (int array[256];//and in it save the numbers)
CPallini 2-Jan-13 15:49pm    
Of course you can.
smss IR 2-Jan-13 11:51am    
Doesn't have anyone an idea??
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.
 
Share this answer
 
Comments
smss IR 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?
smss IR 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900