473,699 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Newbie - Dont' understand << 8

a += (UInt32)(url[k + 0] + (url[k + 1] << 8) + (url[k + 2] << 16) + (url[k +
3] << 24));

I'm trying to understand what the above line of code does. I understand
that the url[] part of (url[k + 1] << 8) returns part of the string but I
don't understand what the << 8 does.
Jul 7 '08 #1
6 1478
"Bishop" <in**@tgscom.co mwrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
>a += (UInt32)(url[k + 0] + (url[k + 1] << 8) + (url[k + 2] << 16) + (url[k
+ 3] << 24));

I'm trying to understand what the above line of code does. I understand
that the url[] part of (url[k + 1] << 8) returns part of the string but
I don't understand what the << 8 does.
It's a binary shift. x<<8 takes the bits of x and shifts them to the left
eight places, introducing zeroes on the right. For instance, 129<<8 would
return 33024. In binary, 129 is 10000001, and 33024 is 100000010000000 0.

Jul 7 '08 #2
Alberto Poblacion skrev:
"Bishop" <in**@tgscom.co mwrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
>a += (UInt32)(url[k + 0] + (url[k + 1] << 8) + (url[k + 2] << 16) +
(url[k + 3] << 24));

I'm trying to understand what the above line of code does. I
understand that the url[] part of (url[k + 1] << 8) returns part of
the string but I don't understand what the << 8 does.

It's a binary shift. x<<8 takes the bits of x and shifts them to the
left eight places, introducing zeroes on the right. For instance, 129<<8
would return 33024. In binary, 129 is 10000001, and 33024 is
100000010000000 0.
In my opinion the statement above should use binary-or (|) instead of
plus (+).

a += (UInt32)(url[k + 0] | (url[k + 1] << 8) | (url[k + 2] << 16) |
(url[k + 3] << 24));

I assume that the url[] array is unsigned bytes.
>

--
Bjørn Brox
Jul 7 '08 #3
On Jul 7, 1:42*pm, "Bishop" <i...@tgscom.co mwrote:
a += (UInt32)(url[k + 0] + (url[k + 1] << 8) + (url[k + 2] << 16) + (url[k +
3] << 24));

I'm trying to understand what the above line of code does. *I understand
that the url[] part of *(url[k + 1] << 8) *returns part of the stringbut I
don't understand what the << 8 does.
Hi,

What I do not understand is what he is doing, some kind of key
verification?
Jul 7 '08 #4
Ignacio Machin ( .NET/ C# MVP ) wrote:
On Jul 7, 1:42 pm, "Bishop" <i...@tgscom.co mwrote:
>a += (UInt32)(url[k + 0] + (url[k + 1] << 8) + (url[k + 2] << 16) + (url[k +
3] << 24));

I'm trying to understand what the above line of code does. I understand
that the url[] part of (url[k + 1] << 8) returns part of the string but I
don't understand what the << 8 does.

What I do not understand is what he is doing, some kind of key
verification?
To me it looks more like a reimplementatio n of BitConverter.To Int32 !

Arne
Jul 8 '08 #5
mdm
On 7 Lug, 21:26, "Ignacio Machin ( .NET/ C# MVP )"
<ignacio.mac... @gmail.comwrote :
On Jul 7, 1:42*pm, "Bishop" <i...@tgscom.co mwrote:
a += (UInt32)(url[k + 0] + (url[k + 1] << 8) + (url[k + 2] << 16) + (url[k +
3] << 24));
I'm trying to understand what the above line of code does. *I understand
that the url[] part of *(url[k + 1] << 8) *returns part of the string but I
don't understand what the << 8 does.

Hi,

What I do not understand is what he is doing, some kind of key
verification?
No, it's taking the 4 8-bit numbers of an ip and building the
corresponding 32 bit number.

M.
Jul 8 '08 #6
If you see a shift of n as a multiplication by 2^n, that is a way to write
in positional notation. As example, with base 10 instead of base 2, what is
proposed can be seen as:

firstDigit + secondDigit * 10 + thirdDigit * 100 + fourthDigit *
1000
except that here, the base is not 10, neither is it 2, but 256 (and x << 8
is like x * 256, assuming x is an integer which will not overflow when
multiplied by 256, as example).
Since the algorithm sum the result, it *may* be part of *some* check (like
someone defining his own-made CRC check), but in itself, it just 'rewrite'
four octets as one 'equivalent' 4-octets wide integer, and add the result
into a variable a.

Vanderghast, Access MVP

"Ignacio Machin ( .NET/ C# MVP )" <ig************ @gmail.comwrote in
message
news:0a******** *************** ***********@59g 2000hsb.googleg roups.com...
On Jul 7, 1:42 pm, "Bishop" <i...@tgscom.co mwrote:
a += (UInt32)(url[k + 0] + (url[k + 1] << 8) + (url[k + 2] << 16) + (url[k
+
3] << 24));

I'm trying to understand what the above line of code does. I understand
that the url[] part of (url[k + 1] << 8) returns part of the string but I
don't understand what the << 8 does.
Hi,

What I do not understand is what he is doing, some kind of key
verification?
Jul 8 '08 #7

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

Similar topics

2
2517
by: SAN CAZIANO | last post by:
can you help me please because I can't understand why the code doesn't seems to function very well: in onkeypress it must verify if insert number or string value in the fiels, but it doesn't seems to function very well (in frontpage it works but here it doesn't) PROGRAMMA IN FRONTPAGE <form method="get" name="f">
4
7840
by: Andre Majorel | last post by:
I'm trying to make a compact <dl> class à la troff .TP where you have Term Definition of the term. Longer Term Definition of the longer term. i.e. if the <dt> text is shorter than the margin-left, the <dd> is on the same line. Otherwise, the <dd> goes on the next line.
10
1676
by: Christopher Benson-Manica | last post by:
Sorry for the lame title, but it's hard to condense what I'm about to say... Here's my situation (my first real C++ situation, yay!). Currently we have a MyTCPThread (don't let the name scare you, this isn't OT) that has a socket member object that has methods Send() and GetLine() for sending and receiving data. I want to subclass MyTCPThread so I can use << and >> as wrappers for Send() and GetLine() (Send() is my primary concern at the...
0
1358
by: Mate Visky | last post by:
hi, i have a little problame. i got this xml file: ---- <?xml version="1.0" encoding="UTF-8" ?> - <out> - <design> - <html> - <!]> </html>
25
2844
by: Steve Richter | last post by:
is it possible to overload the << operator in c# similar to the way it is done in c++ ? MyTable table = new MyTable( ) ; MyTableRow row = new MyTableRow( ) ; row << new MyTableCell( "cell1 text contents" ) ; row << new MyTableCell( "cell2 text contents" ) ; table << row ; thanks,
11
3131
by: Wolfgang Kaml | last post by:
I am not sure if this is more of an expert question, but I am sure that they are out there. I'd like to setup a general application or bin directory on my Win2003.Net Server that will hold some useful utils that more pages on that server can use. As an example, I have created a Page Counter class that opens an Access .mdb file, counts the current entries for that page, and adds a new entry with some information regarding the current...
6
5462
by: Ken Varn | last post by:
I want to add my own custom <STYLE> section in the <HEAD> section of my ASP.NET page within a custom control. Can someone tell me how I can have my custom control add tags to the <HEAD> section of the page dynamically when the page is rendered? -- ----------------------------------- Ken Varn Senior Software Engineer Diebold Inc.
10
6061
by: arnuld | last post by:
WANTED: /* C++ Primer - 4/e * * Exercise: 9.26 * STATEMENT * Using the following definition of ia, copy ia into a vector and into a list. Use the single iterator form of erase to remove the elements with odd values from your list * and the even values from your vector.
3
1427
by: =?Utf-8?B?Y2xhcmE=?= | last post by:
Hi all, how to understand the following declaration in MSDN about nullable structure <SerializableAttribute_ Public Structure Nullable(Of T As Structure) I can : dim id as nullable(of integer), but integer is not a structure, so what is the function of the AS Structure here?
0
8687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9174
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9035
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8914
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5875
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4376
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2009
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.