从十进制到八进制的转换 [英] Conversion From Decimal To Octal

查看:61
本文介绍了从十进制到八进制的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计我已经制作了一个转换器,在VB.NET中将十进制数转换为八进制数,但它只将十进制数的最多7位数转换为八进制数。如果它超过7位,则显示内存溢出消息。如何要解决这个问题吗?





这是代码:

Guys I have made a convertor that converts a decimal number to a octal number in VB.NET,but it converts only upto 7 digits of decimal number to Octal.If it exceeds 7 digits "Memory Overflow" message is displayed.How To solve this problem guys?


Here Is The Code:

Dim s1,s2 As Atring
Dim i1,i2 As Integer

s1=textbox1.Text
i1=Convert.ToInt64(s1, 10)
s2=Convert.ToString(i1, 8)
i2=Convert.ToInt64(s2, 8)
MsgBox(s2)



但此代码最多只能输入7个字符。


but this code is limited only up to 7 characters of input.

推荐答案

如果没有看到您的代码,我们就无法提供帮助。

phil.o给了你指导如何开始调试你的应用程序,但是......你是否意识到.NET可以为你做这个?

Without seeing your code, we can't be that helpful.
phil.o has given you instruction in how to start debugging your application, but...did you realise that .NET can do this for you?
Dim inp As Integer = 1234567890
Dim oct As String = Convert.ToString(inp, 8)
Console.WriteLine("The Octal value of {1} is {2}", inp, oct)


没有提供任何代码,唯一的解决方案是:

- 在处理转换的方法的开头放置一个beakpoint。

- 你的项目处于调试模式(Visual Studio中的F5)。

- 继续从线到排队并仔细观察变量的值;你不得不想知道你对他们的期望是什么,以及你实际得到的是什么;差异将指出问题。







查看您的代码,然后解决方案2原始格里夫是你想要做的事情,你可以按照你想要的方式做到,但是没有限制。



我只会改变你获得你的方式来自textBox的 Int32 值:

Without any code provided, the only solution left for you is to:
- put a beakpoint at the beginning of the method handling the conversion.
- lauch your project in debug mode (F5 in Visual Studio).
- go on from line to line and watch carefully for the values of your variables ; you have to wonder what it is you expect for them, and what you actually get; the difference will point the problem.

[edit]

Seeing your code, then Solution 2 by Original Griff is the one that does exactly what you want to do the way you want to do it, but without limitations.

I would just change the way you get your Int32 value from your textBox:
If (Int32.TryParse(s1, i1))
   s2 = Convert.ToString(i1, 8)
End If





[/ edit]



[/edit]


这篇关于从十进制到八进制的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆