值转换为二进制代码 [英] value to binary code

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

问题描述

在vb.net2010中将文本中的位置字符串转换为十进制到二进制l希望对我有帮助
例子
文字为:lam waersoft l将来将进行工程设计

解决方案

字符串中的字符.在每个值"点处,以您感兴趣的任意数字基数显示字符索引,因此对于位置12,它看起来像:

十进制:12
十六进制:x0C
八进制:014
二进制:01100 


我不确定我是否已经理解您的问题,但看起来您是否想要在字符串中找到的每个单词的位置和位置的二进制表示形式?

如果确实如此,则类似的事情可能对您有用;

  Sub  Main()
         Dim  str  As  字符串 = " 

         Dim 单词 As  字符串 = 字符串.空
         Dim 开始 As  整数 =  0 

        对于 i  As  整数 =  0  长度- 1 
             Dim  c  As   Char  = str.Chars (一世)
            如果 字符.IsWhiteSpace(c)然后
                如果 不是 字符串.IsNullOrWhiteSpace(word) 然后
                    Console.WriteLine(" ,单词,开始,Convert.ToString(开始, 2 ))
                结束 如果
                字= 字符串.空
            其他
                如果 字符串.IsNullOrEmpty(word)然后开始=我
                字=字+ c
            结束 如果
        下一步
    结束  



会打印类似的东西;

在位置 2 上找到单词' am' (二进制 10 ) 在位置 5 上找到单词' waersoft' (二进制 101 ) 在位置 14 上找到单词' I' (二进制 1110 ) 在位置 16 上找到单词' 将' (二进制 10000 ) 在位置 21 上找到的单词' to' (二进制 10101 ) 在位置 24 上找到单词' 工程' (二进制 11000 ) 在位置 36 上找到单词' in' (二进制 100100 )



希望这会有所帮助,
弗雷德里克(Fredrik)


convert position string in text is decimal to binary in vb.net2010 l hope to help me
example
text is:lam waersoft l will to engineering in future<
my question what is the value of position in text to all word such as;l,am and convert to this value to binary code

解决方案

Create a loop to iterate over the characters in the string. At each ''value'' point display the character index in whatever number base you are interested in, so for position 12 it would look something like:

Decimal: 12
Hex:     x0C
Octal:   014
Binary:  01100


I am not sure I''ve understood your question but it looks like you want the position and the positions binary representation of each word found in a string?

If that is indeed the case something like this might work for you;

Sub Main()
        Dim str As String = "I am waersoft I will to engineering in future"

        Dim word As String = String.Empty
        Dim start As Integer = 0

        For i As Integer = 0 To str.Length - 1
            Dim c As Char = str.Chars(i)
            If Char.IsWhiteSpace(c) Then
                If Not String.IsNullOrWhiteSpace(word) Then
                    Console.WriteLine("Word '{0}' found at position {1} (binary value {2})", word, start, Convert.ToString(start, 2))
                End If
                word = String.Empty
            Else
                If String.IsNullOrEmpty(word) Then start = i
                word = word + c
            End If
        Next
    End Sub



Which would print something like;

Word 'I' found at position 0 (binary value 0)
Word 'am' found at position 2 (binary value 10)
Word 'waersoft' found at position 5 (binary value 101)
Word 'I' found at position 14 (binary value 1110)
Word 'will' found at position 16 (binary value 10000)
Word 'to' found at position 21 (binary value 10101)
Word 'engineering' found at position 24 (binary value 11000)
Word 'in' found at position 36 (binary value 100100)



Hope this helps,
Fredrik


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

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