I want to show the binary equivalentcy of the numbers 1 -
256. I am writing my program as a console application
and I do not want to use any String formats. Can anyone
please get me started on the right track. Thank you in
advance.
D 11 2336
Hello,
"D" <de********@earthlink.net> schrieb: I want to show the binary equivalentcy of the numbers 1 - 256. I am writing my program as a console application and I do not want to use any String formats. Can anyone please get me started on the right track.
\\\
Dim i As Integer
For i = 1 To 256
Debug.WriteLine(Convert.ToString(i, 2))
Next i
///
--
Herfried K. Wagner
MVP · VB Classic, VB.NET http://www.mvps.org/dotnet
first of all thank you for your guidence. I had to first
write the code as follows for it to display:
Dim i As Integer
For i = 1 To 256
Console.WriteLine(Convert.ToString(i, 2))
Next i
However, I found that some of the numbers were
represented with only 6 bits while others showed being
represented as 9 bits and so on. also do you know of a
way to print the results without using the "ToString"
Thank you so much already. You have been a great help. -----Original Message----- Hello,
"D" <de********@earthlink.net> schrieb: I want to show the binary equivalentcy of the numbers
1 - 256. I am writing my program as a console application and I do not want to use any String formats. Can anyone please get me started on the right track.
\\\ Dim i As Integer For i = 1 To 256 Debug.WriteLine(Convert.ToString(i, 2)) Next i ///
-- Herfried K. Wagner MVP · VB Classic, VB.NET http://www.mvps.org/dotnet
.
Hi D,
It's possible to do this by testing each bit in turn and outputting either a "0" or a "1" but it's a lot of work compared to
using the built-in functions.
Why aren't you allowed to use string functions? What's it all for?
Regards,
Fergus
Hey Fergus
It is for not particular reason other than the fact that
is how I want to do it. maybe you could look at my code
and tell me what I'm doing wrong. I want to have 8
columns but I seem to have my formatting all wrong.
Derrick -----Original Message----- Hi D,
It's possible to do this by testing each bit in turn
and outputting either a "0" or a "1" but it's a lot of
work compared tousing the built-in functions.
Why aren't you allowed to use string functions?
What's it all for? Regards, Fergus
.
I have no idea what you are trying to achieve with the side, row and column
stuff but, if I interpret your 'problem correctly what you looking for is to
have each value shown as 'binary' with all 8 bits displayed thus:
1 = 00000001
256 = 11111111
This can be simply achieved by using:
Convert.ToString(counter, 2).PadLeft(8, "0"c)
Your restriction on using string functions is invalid because
Console.WriteLine is, effectivly, a string function.
Looks like some sort of acedemic assignment to me.
"Derrick" <de********@earthlink.net> wrote in message
news:2d****************************@phx.gbl... Sub Main() Console.WriteLine("Binary Table") Console.WriteLine() Dim counter As Integer Dim row As Integer = 1 Dim column As Integer Dim side As Integer = 8
If side <= 20 Then
While row <= side 'control row column = 1
While column <= side For counter = 1 To 256 Console.WriteLine(Convert.ToString(counter, 2)) column += 1 Next counter
End While
Console.WriteLine() row += 1 End While End If
End Sub
End Module-----Original Message----- Hey Fergus
It is for not particular reason other than the fact that is how I want to do it. maybe you could look at my code and tell me what I'm doing wrong. I want to have 8 columns but I seem to have my formatting all wrong.
Derrick-----Original Message----- Hi D,
It's possible to do this by testing each bit in turnand outputting either a "0" or a "1" but it's a lot of work compared tousing the built-in functions.
Why aren't you allowed to use string functions? What's it all for? Regards, Fergus
.
.
Actually, this very much sounds like a classroom project that has been
assigned, so here's the spoiler...
Sub Main()
Console.WriteLine("Binary Table")
Console.WriteLine()
Dim counter As Integer
Dim bitpos as Integer
For counter = 1 to 256
For bitpos = 8 to 0 Step -1
If (counter And (2^bitpos)) > 0
Console.Write("1")
Else
Console.Write("0")
End If
Next
Console.WriteLin()
Next
End Sub
The bitpos variable is 8 to 0 because you want the bitrep for 256, which
exceeds the 255 8-bit limit.
"Derrick" <de********@earthlink.net> wrote in message
news:2d****************************@phx.gbl... Sub Main() Console.WriteLine("Binary Table") Console.WriteLine() Dim counter As Integer Dim row As Integer = 1 Dim column As Integer Dim side As Integer = 8
If side <= 20 Then
While row <= side 'control row column = 1
While column <= side For counter = 1 To 256 Console.WriteLine(Convert.ToString(counter, 2)) column += 1 Next counter
End While
Console.WriteLine() row += 1 End While End If
End Sub
End Module-----Original Message----- Hey Fergus
It is for not particular reason other than the fact that is how I want to do it. maybe you could look at my code and tell me what I'm doing wrong. I want to have 8 columns but I seem to have my formatting all wrong.
Derrick-----Original Message----- Hi D,
It's possible to do this by testing each bit in turnand outputting either a "0" or a "1" but it's a lot of work compared tousing the built-in functions.
Why aren't you allowed to use string functions? What's it all for? Regards, Fergus
.
.
Hi Derrick,
|| While row <= side 'control row
|| column = 1
|| While column <= side
|| For counter = 1 To 256
|| Console.WriteLine(Convert.ToString(counter, 2))
|| column += 1
|| Next counter
|| End While
|| Console.WriteLine()
|| row += 1
|| End While
You've got the right idea with wanting two nested loops. However, as you've found, you're getting loads of consecutive lists of
256.
What you need is to do is 8 values horizontally on the same line. Then go to the next line and do the next 8. And so on. You use
Console.Write() when you want to go stay on the same line. Your Console.WriteLine() is in the right place.
For your grid of values it depends on whether you want the values horizontal or vertical. If horizontal, your first row would be
1, 2, 3, 4, 5, 6, 7, 8. If vertical, it would be 1, 33, 65, 97, 139, etc.
At the moment you are using While loops. However, as you know how many rows and columns there are and as you are always going up
by 1, it would be better to use For loops.
Take out the counter loop and increment it manually inside tyour row and column loops.
That's all for now. Come back to me with the next version. :-)
Regards,
Fergus
Hi Richard,
You meany!! I was going to lead him there with carefully staged questions, lol.
Changing topic completely (if stephanie will let me [pokes out tongue]), did you come to any conclusions about creating your
multitude of classes and their properties?
Regards,
Fergus
> 256 = 11111111
Hi, that's incorrect. The number 256 = 100000000
--
HTH,
-- Tom Spink, Über Geek
Please respond to the newsgroup,
so all can benefit
"Maybe it's a game called 'Punish the User'"
"Stephany Young" <st******@sysoft.co.nz> wrote in message
news:eg**************@TK2MSFTNGP10.phx.gbl... I have no idea what you are trying to achieve with the side, row and
column stuff but, if I interpret your 'problem correctly what you looking for is
to have each value shown as 'binary' with all 8 bits displayed thus:
1 = 00000001 256 = 11111111
This can be simply achieved by using:
Convert.ToString(counter, 2).PadLeft(8, "0"c)
Your restriction on using string functions is invalid because Console.WriteLine is, effectivly, a string function.
Looks like some sort of acedemic assignment to me.
"Derrick" <de********@earthlink.net> wrote in message news:2d****************************@phx.gbl... Sub Main() Console.WriteLine("Binary Table") Console.WriteLine() Dim counter As Integer Dim row As Integer = 1 Dim column As Integer Dim side As Integer = 8
If side <= 20 Then
While row <= side 'control row column = 1
While column <= side For counter = 1 To 256 Console.WriteLine(Convert.ToString(counter, 2)) column += 1 Next counter
End While
Console.WriteLine() row += 1 End While End If
End Sub
End Module-----Original Message----- Hey Fergus
It is for not particular reason other than the fact that is how I want to do it. maybe you could look at my code and tell me what I'm doing wrong. I want to have 8 columns but I seem to have my formatting all wrong.
Derrick >-----Original Message----- >Hi D, > > It's possible to do this by testing each bit in turnand outputting either a "0" or a "1" but it's a lot of work compared to >using the built-in functions. > > Why aren't you allowed to use string functions? What's it all for? > >Regards, >Fergus > > >. > .
Hi, May I ask why 1 to 256? 1-255 are 8-bit numbers, but 256 is a 9-bit
number. Are you sure you don't want 0-255, there are still 256 numbers in
0-255.
--
HTH,
-- Tom Spink, Über Geek
Please respond to the newsgroup,
so all can benefit
"Maybe it's a game called 'Punish the User'"
"Derrick" <de********@earthlink.net> wrote in message
news:2d****************************@phx.gbl... Sub Main() Console.WriteLine("Binary Table") Console.WriteLine() Dim counter As Integer Dim row As Integer = 1 Dim column As Integer Dim side As Integer = 8
If side <= 20 Then
While row <= side 'control row column = 1
While column <= side For counter = 1 To 256 Console.WriteLine(Convert.ToString(counter, 2)) column += 1 Next counter
End While
Console.WriteLine() row += 1 End While End If
End Sub
End Module-----Original Message----- Hey Fergus
It is for not particular reason other than the fact that is how I want to do it. maybe you could look at my code and tell me what I'm doing wrong. I want to have 8 columns but I seem to have my formatting all wrong.
Derrick-----Original Message----- Hi D,
It's possible to do this by testing each bit in turnand outputting either a "0" or a "1" but it's a lot of work compared tousing the built-in functions.
Why aren't you allowed to use string functions? What's it all for? Regards, Fergus
.
.
Hi,
"> > 256 = 11111111 Hi, that's incorrect. The number 256 = 100000000
Or
255=11111111
:-)
Cor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Christian Stigen Larsen |
last post by:
A signed int reserves one bit to signify whether a number is positive or
negative. In light of this, a colleague asked me whether there existed an
int in C++ that was -0, a zero with the negative...
|
by: J. Campbell |
last post by:
OK...I'm in the process of learning C++. In my old (non-portable)
programming days, I made use of binary files a lot...not worrying
about endian issues. I'm starting to understand why C++ makes...
|
by: bearophileHUGS |
last post by:
Hello, I have four things to ask or to suggest, sorry if they seem
basic or already discussed.
-------------------
I am still ignorant about Tkinter. This little program, after pressing
the...
|
by: Gaijinco |
last post by:
Is there any way to declare a variable as a binary so that if the
variable "var" holds the value of 1001, then ++var = 1010?
|
by: Tanuki |
last post by:
Hi All:
I encounter a programming problem recently. I need to read a binary
file. I need to translate the binary data into useful information. I
have the format at hand, like 1st byte = ID,...
|
by: Yeow |
last post by:
hello,
i was trying to use the fread function on SunOS and ran into some
trouble.
i made a simple test as follows:
i'm trying to read in a binary file (generated from a fortran code)
that...
|
by: vim |
last post by:
hello everybody
Plz tell the differance between binary file and ascii
file...............
Thanks
in advance
vim
|
by: smith4894 |
last post by:
Hello all,
I'm working on writing my own streambuf classes (to use in my custom
ostream/isteam classes that will handle reading/writing data to a
mmap'd file).
When reading from the mmap...
|
by: elliotng.ee |
last post by:
I have a text file that contains a header 32-bit binary. For example,
the text file could be:
%%This is the input text
%%test.txt
Date: Tue Dec 26 14:03:35 2006...
|
by: Andrea |
last post by:
Hi, I'm a newbie i want to know how can i convert string to its binary
representation, i want to write a program where an example string
"hello world" is transformed in his binary representation...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |