473,395 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Decimal To Binary Function Does Not Work

I am using the following sub but i am getting inaccurate output

Public Function Convert(ByVal Base As Integer, ByVal Number As Integer) As Strin

D
If Not Number / Base = 0 The
Convert &= (Number Mod Base).ToStrin
Number = Number / Bas
Els
Return StrReverse(Convert
End I
Loo

End Functio

Does any one know why this is not working

Thanks for any help in advance
Nov 20 '05 #1
1 2141
WStoreyII,
Do you need to use floating division?

I would expect that Integer division would be better.

Remember "/" is floating division, while "\" is integer division.

Or are you referring to the fact your routine drops the leading digit?
Have you considered using System.Convert.ToString(value as Integer, tobase
As Integer) instead?

Have you tried:
Public Function Convert(ByVal Base As Integer, ByVal Number As Integer) As String
Do
If number <> 0 Then
Convert &= (Number Mod Base).ToString
Number = Number \ Base
Else
Return StrReverse(Convert)
End If
Loop

End Function

Note the above returns nothing when the input = 0!

Hope this helps
Jay
"WStoreyII" <pa**********@sbcglobal.net> wrote in message
news:68**********************************@microsof t.com... I am using the following sub but i am getting inaccurate output

Public Function Convert(ByVal Base As Integer, ByVal Number As Integer) As String
Do
If Not Number / Base = 0 Then
Convert &= (Number Mod Base).ToString
Number = Number / Base
Else
Return StrReverse(Convert)
End If
Loop

End Function

Does any one know why this is not working?

Thanks for any help in advance

Nov 20 '05 #2

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

Similar topics

21
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
687
by: cody | last post by:
no this is no trollposting and please don't get it wrong but iam very curious why people still use C instead of other languages especially C++. i heard people say C++ is slower than C but i can't...
7
by: Golan | last post by:
Hi, I need to convert a Binary value to Decimal. I've been told that the value is an unsigned one. How can I do this? I use memcpy into an unsigned char variable, but when I print the value I got...
2
by: Steve Summit | last post by:
-----BEGIN PGP SIGNED MESSAGE----- It's often explained that the reason for some of the imprecision in C's definition is so that C can be implemented on different kinds of machines -- say, those...
2
by: Tukeind | last post by:
Hello, I am receiving the following error: error C2065: 'to_binary' : undeclared identifier while running the code below. If anyone can help I'll appreciate it? Thank you, Tukeind
5
by: sweeet_addiction16 | last post by:
im coding in c....i need to accept an integer value(decimal) and then after converting it into hexadecimal value i need to write it into a file.i do not need to print it..so using fprintf along...
3
by: zgfareed | last post by:
My program converts decimal numbers from to binary and hexadecimal. I am having trouble with my output which is supposed to be in a certain format. Binary needs to be in the format of XXXX XXXX...
1
by: girl23 | last post by:
Hi there ]i am new to C programming and totally lost. iam trying to convert decimal to binary. here is what i did please ignore the case h and m. I am trying to get case 'b' to work. i do not...
0
Frinavale
by: Frinavale | last post by:
Convert a Hex number into a decimal number and a decimal number to Hex number This is a very simple script that converts decimal numbers into hex values and hex values into decimal numbers. The...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.