473,471 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Octal Integer Constants

Hi,

I have a whole bunch of integer constants that are best given in octal
(PDP-1 opcodes). It makes a huge difference in readability and authenticity
if these
can be entered in octal. I haven't found a way to do this. Is there one?

Thanks,
Gary
May 26 '07 #1
7 11355
On Fri, 25 May 2007 19:03:48 -0700, Gary Brown <ga********@charter.net>
wrote:
I have a whole bunch of integer constants that are best given in octal
(PDP-1 opcodes). It makes a huge difference in readability and
authenticity
if these can be entered in octal. I haven't found a way to do this. Is
there one?
C# doesn't have octal literals. However, a couple of possible workarounds:

* VB does support octal literals (use "&O" before the number) so you
could define your constants in a VB.NET class and reference them from C#

* Depending on how the literals are to be used, you could just enter
them as hexadecimal literals that read visually as octal (sort of like
BCD) and then have some code that preprocesses them by taking out the
4-bit gaps in the binary values. I think this would work best if you're
using the literals to initialize an array or something like that, but even
if you're using them for named constants, you could "fake it" by instead
defining fields that are preprocessed at run-time (sorry if that sounds
oxymoronic...I hope you get what I mean :) ).

Using them as named constants, I think you'd have to gain a lot of
readability to justify the hack, since you'd sacrifice the minor
performance gain actual literal constants get you, as well as the
read-only nature of constants, and of course you'd have to have a block of
code somewhere that goes through and does the run-time preprocessing. All
of that's a pain; I would probably just write the hex, and if readability
was an issue I'd include the octal value in a comment next to it.

But for initializing an array, I think even the second method would work
pretty well. :)

Why you're looking for "authenticity" in source code, especially when
writing PDP-related code in C#, I'm not really clear on. But I'll take
your word for it that that's a desirable goal for some reason. :)

Pete
May 26 '07 #2
On Fri, 25 May 2007 20:48:44 -0700, Peter Duniho
<Np*********@nnowslpianmk.comwrote:
[...]
* Depending on how the literals are to be used, you could just
enter them as hexadecimal literals that read visually as octal (sort of
like BCD) and then have some code that preprocesses them by taking out
the 4-bit gaps in the binary values. [...]
Of course, I meant 1-bit gaps. Sorry if my mistyping confused things. :(
May 26 '07 #3
"Gary Brown" <ga********@charter.netwrote in message
news:O9**************@TK2MSFTNGP03.phx.gbl...
Hi,

I have a whole bunch of integer constants that are best given in octal
(PDP-1 opcodes). It makes a huge difference in readability and
authenticity if these
can be entered in octal. I haven't found a way to do this. Is there one?
How about this:

const int O_11 = 9;
const int O_10167 = 4215;

--
LTP

:)
May 26 '07 #4
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Fri, 25 May 2007 20:48:44 -0700, Peter Duniho
<Np*********@nnowslpianmk.comwrote:
>[...]
* Depending on how the literals are to be used, you could just
enter them as hexadecimal literals that read visually as octal (sort of
like BCD) and then have some code that preprocesses them by taking out
the 4-bit gaps in the binary values. [...]

Of course, I meant 1-bit gaps. Sorry if my mistyping confused things. :(
Or (possibly better) enter them as strings and write your own routine to
convert them to integers in octal.
May 26 '07 #5
>I have a whole bunch of integer constants that are best given in octal
>(PDP-1 opcodes). It makes a huge difference in readability and
authenticity
if these can be entered in octal. I haven't found a way to do this. Is
there one?

* Depending on how the literals are to be used, you could just enter
them as hexadecimal literals that read visually as octal (sort of like
BCD) and then have some code that preprocesses them by taking out the
That is essentially what I did. I had

const int add = 0400000,

which I transformed to a call

ConvertOp(SW, "add", 0400000);

with a macro. "Convert" converted the decimal 0400000 to hex then
output it with the mnemonic to a file. I pasted the file contents back
into the source yielding

const int add = 0x20000, // 0400000

Using Basic as someone suggested was also a good idea but I
don't have Basic installed.

It would have been so much easier if literals beginning with 0 were
octal as I originally thought.

Thanks,
Gary
May 26 '07 #6
It would have been so much easier if literals beginning with 0 were
octal as I originally thought.
I think you've stumbled onto the only legitimate use of octal within the
past 30 years! :)
May 26 '07 #7
Gary Brown wrote:
Hi,

I have a whole bunch of integer constants that are best given in octal
(PDP-1 opcodes). It makes a huge difference in readability and authenticity
if these
can be entered in octal. I haven't found a way to do this. Is there one?
Surprisingly:

private const int c1 = 011;

does not work as expected.

But:

private static readonly int c2 = Convert.ToInt32("011", 8);

could be a possible workaround.

Arne
May 26 '07 #8

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

Similar topics

5
by: KB | last post by:
Hi, This may be a rudimentary question: How to convert a string like '777' to an octal integer like 0777, so that it can be used in os.chmod('myfile',0777)? I know the leading zero is...
7
by: Nicholas | last post by:
How can I get the largest possible value of the Integer Constants and use it in the program for these types: 1. int 2. long 3. unsigned short Thanks
7
by: Jon Shemitz | last post by:
I was experimenting with implicit typing of integer constants, and found to my surprise that in MS C# 1.1 (VS.2003) you can write code like double Large = 18446744073709551615; This is quite...
33
by: gk245 | last post by:
I mean, anything that follows a 0 is automatically turned into a octal number. I want to have a integer variable that will hold numbers as integers even if they begin with a zero. for example:...
15
by: jaks.maths | last post by:
How to convert negative integer to hexadecimal or octal number? Ex: -568 What is the equivalent hexadecimal and octal number??
5
by: =?Utf-8?B?QW1pciBUb2hpZGk=?= | last post by:
Hi I have two constant integers and when I try to compare their values, I get error: Operator '==' cannot be applied to operands of type ... Here is a cut down version of my code public...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.