473,385 Members | 1,487 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,385 software developers and data experts.

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 1455
"Bishop" <in**@tgscom.comwrote in message
news:%2****************@TK2MSFTNGP05.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 1000000100000000.

Jul 7 '08 #2
Alberto Poblacion skrev:
"Bishop" <in**@tgscom.comwrote in message
news:%2****************@TK2MSFTNGP05.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
1000000100000000.
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.comwrote:
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.comwrote:
>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 reimplementation of BitConverter.ToInt32 !

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.comwrote:
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**********************************@59g2000h sb.googlegroups.com...
On Jul 7, 1:42 pm, "Bishop" <i...@tgscom.comwrote:
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
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...
4
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...
10
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,...
0
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
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...
11
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...
6
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...
10
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...
3
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
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...
0
isladogs
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.