C#到VB.NET转换

编程入门 行业动态 更新时间:2024-10-28 13:25:19
本文介绍了C#到VB.NET转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在把一些C#代码转换成VB.NET作为一个学习 的练习,我正在为我的缺乏而苦苦挣扎 理解一些C#语法。 C#代码是: public const int LOCSIG =''P''| (''K''<< 8)| (3 << 16)| (4 我对人物''P''和' ''K''作为整数常量的一部分 以及管道是什么<<意味着。 TIA, -Matt

I''m playing around with converting some C# code to VB.NET as a learning exercise and I''m running into a little confussion for my lack of understanding some C# syntax. The C# code is: public const int LOCSIG = ''P'' | (''K'' << 8) | (3 <<16) | (4 << 24) Can anybody explain to me what this is doing and possibly give me a VB.NET equivalent? I''m confused about the characters ''P'' & ''K'' as part of an integer constant and what the pipes are along with what << means. TIA, -Matt

推荐答案

在大学里,我们曾经互相挑战。我们会给另外一块 块真的很模糊的C代码,看看对方是否可以找出它没有运行它的功能。这段代码的作者必须有 参加我的学校:-) 管道是按位OR。 <<<运算符是一个逻辑左移。在C中, 在单引号之间放置一个字符与获取字符的数字 值相同。请参阅 www.asciitable/ 因此,这个表达式只是一个使用一系列而不是钝的二进制表达式创建的整数值。 In college, we used to challenge eachother. We''d give eachother blocks of really really obscure C code and see if the other person could figure out what it does without running it. The author of this bit of code must have attended my school :-) The pipes are bitwise OR. The << operator is a logical left shift. In C, placing a character between single quotes is the same as getting the numeric value of the character. see www.asciitable/ So, this expression is simply an integer value created using a series of rather obtuse binary expressions. public const int LOCSIG ='' P''| (''K''<< 8)| (3 << 16)| (4 << 24)等于0000 0100 0000 0011 0100 1001 0101 0000 或hex 0403 4B50 HTH, - --- Nick Malik [微软] MCSD,CFPS,认证Scrummaster blogs.msdn/nickmalik 免责声明:本论坛中表达的意见是我自己的,而不是我雇主的b $ b代表。 我不代表我的雇主回答问题。我只是一个帮助程序员的程序员。 - " Matthew Hood" <博士*********** @ Yahoo>在消息中写道 新闻:OZ ************** @ TK2MSFTNGP12.phx.gbl ...我正在将一些C#代码转换为VB .NET作为一种学习练习,我因为缺乏对C#语法的理解而陷入困境。 C#代码是: public const int LOCSIG =''P''| (''K''<< 8)| (3 << 16)| (4 << 24) 任何人都可以向我解释这是做什人物''P''& ''K''作为整数常量的一部分以及管道与什么<<意味着。 TIA, -Matt public const int LOCSIG = ''P'' | (''K'' << 8) | (3 <<16) | (4 << 24) which is equal to 0000 0100 0000 0011 0100 1001 0101 0000 or hex 0403 4B50 HTH, -- --- Nick Malik [Microsoft] MCSD, CFPS, Certified Scrummaster blogs.msdn/nickmalik Disclaimer: Opinions expressed in this forum are my own, and not representative of my employer. I do not answer questions on behalf of my employer. I''m just a programmer helping programmers. -- "Matthew Hood" <Dr***********@Yahoo> wrote in message news:OZ**************@TK2MSFTNGP12.phx.gbl... I''m playing around with converting some C# code to VB.NET as a learning exercise and I''m running into a little confussion for my lack of understanding some C# syntax. The C# code is: public const int LOCSIG = ''P'' | (''K'' << 8) | (3 <<16) | (4 << 24) Can anybody explain to me what this is doing and possibly give me a VB.NET equivalent? I''m confused about the characters ''P'' & ''K'' as part of an integer constant and what the pipes are along with what << means. TIA, -Matt

Public Const LOCSIG As Int32 = AscW(" ; Pc)或(AscW(Kc)<< 8)或(3 << 16)或(4 <24) 字符需要转换为ASCII值才能使用 这个等式。 | =或 << =二进制向左移动 Public Const LOCSIG As Int32=AscW("P"c)Or(AscW("K"c)<<8)Or(3<<16)Or(4<<24 ) Characters need to be converted to their ASCII value before they can be used in this kind of equation. | = Or << = Binary Shift to the Left =二进制向右移位

帮助解释二进制的示例表转移。 Binary(Base 2)|十进制等效项|替代方程 ---------------------------------------- ------------------------ 001010<< 1 = 010100 10 << 1 1 = 20 10 *(2 * 1)= 20 001011<< 1 = 010110 11 << 1 1 = 22 11 *(2 * 1)= 22 001010<< 2 = 101000 10 << 2 = 40 10 *(2 * 2)= 40 001011<< 2 = 101100 11 > 1 = 5 10 \(2 * 1)= 5 1011>> 1 = 0101 11> 1 = 5 11 \(2 * 1)= 5 1010>> 2 = 0010 10>> 2 = 2 10 \(2 * 2)= 2 1011>> 2 = 0010 11> 2 = 2 11 \(2 * 2)= 2 ----------------------------- ----------------------------------- - Mick Doherty dotnetrix.co .uk / nothing.html " Matthew Hood" <博士*********** @ Yahoo>在消息中写道 新闻:OZ ************** @ TK2MSFTNGP12.phx.gbl ...我正在将一些C#代码转换为VB .NET作为一种学习练习,我因为缺乏对C#语法的理解而陷入困境。 C#代码是: public const int LOCSIG =''P''| (''K''<< 8)| (3 << 16)| (4 << 24) 任何人都可以向我解释这是做什人物''P''& ''K''作为整数常量的一部分以及管道与什么<<意思是。 TIA, -Matt

Example table to help explain Binary Shift. Binary (Base 2) | Decimal Equivelant | Alternative Equation ---------------------------------------------------------------- 001010 << 1 = 010100 10 << 1 = 20 10 * (2 * 1) = 20 001011 << 1 = 010110 11 << 1 = 22 11 * (2 * 1) = 22 001010 << 2 = 101000 10 << 2 = 40 10 * (2 * 2) = 40 001011 << 2 = 101100 11 << 2 = 44 11 * (2 * 2) = 44 1010 >> 1 = 0101 10 >> 1 = 5 10 \ (2 * 1) = 5 1011 >> 1 = 0101 11 >> 1 = 5 11 \ (2 * 1) = 5 1010 >> 2 = 0010 10 >> 2 = 2 10 \ (2 * 2) = 2 1011 >> 2 = 0010 11 >> 2 = 2 11 \ (2 * 2) = 2 ---------------------------------------------------------------- -- Mick Doherty dotnetrix.co.uk/nothing.html "Matthew Hood" <Dr***********@Yahoo> wrote in message news:OZ**************@TK2MSFTNGP12.phx.gbl... I''m playing around with converting some C# code to VB.NET as a learning exercise and I''m running into a little confussion for my lack of understanding some C# syntax. The C# code is: public const int LOCSIG = ''P'' | (''K'' << 8) | (3 <<16) | (4 << 24) Can anybody explain to me what this is doing and possibly give me a VB.NET equivalent? I''m confused about the characters ''P'' & ''K'' as part of an integer constant and what the pipes are along with what << means. TIA, -Matt

" Matthew Hood" <博士*********** @ Yahoo>写道: "Matthew Hood" <Dr***********@Yahoo> wrote: public const int LOCSIG =''P''| (''K''<< 8)| (3<< 16)| (4 << 24)任何人都可以向我解释这是做什么的 public const int LOCSIG = ''P'' | (''K'' << 8) | (3 <<16) | (4 << 24) Can anybody explain to me what this is doing

对于 实例,P''是80)。 - 管道表示按位OR运算:结果的二进制 表示每个数字都有1个,其中任何两个表达式都围绕着将有一个1. - << operator是一个按位左移操作:结果的二进制 表示是旋转的。左边是由右边操作数指示的 位置的数量。 谁写了那行代码并且没有评论它应该拍摄。 P.

- The characters will be treated as ASCII values (so ''P'', for instance, is 80). - The pipes represent a bitwise OR operation: the binary representation of the result has a 1 in each digit where either of the two expressions around | would have a 1. - The << operator is a bitwise left shift operation: the binary representation of the result is "rotated" to the left by the number of positions indicated by the right-hand operand. Whoever wrote that line of code and didn''t comment it should be shot. P.

更多推荐

C#到VB.NET转换

本文发布于:2023-05-27 23:13:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/306149.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:VB   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!