Click here to Skip to main content
12,892,469 members (45,925 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++
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)
Posted 2-Jan-13 0:52am
smss IR407
Richard MacCutchan 2-Jan-13 7:50am
You already have that type: char.
Rate this: bad
Please Sign up or sign in to vote.

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: bad
Please Sign up or sign in to vote.

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)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170424.1 | Last Updated 2 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100