为什么左移运算符为硬编码值打印不同的结果和大整数

时间:2017-12-31 21:36:48

标签: c# bitwise-operators

当使用左移和大整数时我会得到不同的结果,当我使用硬编码时,为什么会这样,如何克服?

    BigInteger num = 1779033703;
    BigInteger result = num << 30;
    Console.WriteLine(result);
    Console.WriteLine(1779033703 << 30);

结果

1910222893216694272

-1073741824

1 个答案:

答案 0 :(得分:2)

因为常规<?php include('includes/sessions.php'); include('includes/db_connection.php'); include('includes/functions.php'); include('includes/header.php'); include('includes/navbar-logged.php'); ?> <?php $crawlId = isset($_GET['urlId']) ? $_GET['urlId'] : ''; ?> <?php if (!isset($_GET['page'])) { $page = 1; } else { $page = $_GET['page']; } $userInfo = get_logged_in_users_details($member); $canEdit = false; if ($userInfo['user_class'] === 'Site Administrator') { $canEdit = true; } $sort = isset($_GET['sort']) ? $_GET['sort'] : 'domain_id'; $max_results = 500; $from = ($page * $max_results) - $max_results; if (isset($crawlId)) { $rows = DB::getInstance()->select(" SELECT * FROM `domains` WHERE `domain_available`='Y' AND `domain_crawler_id`='{$crawlId}' ORDER BY `{$sort}` DESC LIMIT :from, :max_results", [ 'from' => [ 'type' => PDO::PARAM_INT, 'value' => $from ], 'max_results' => [ 'type' => PDO::PARAM_INT, 'value' => $max_results ] ]); } else { $rows = DB::getInstance()->select(" SELECT * FROM `domains` WHERE `domain_available`='Y' AND `domain_category`!='N/A' AND `domain_crawler_id`='0' ORDER BY `{$sort}` DESC LIMIT :from, :max_results", [ 'from' => [ 'type' => PDO::PARAM_INT, 'value' => $from ], 'max_results' => [ 'type' => PDO::PARAM_INT, 'value' => $max_results ] ]); } if (isset($crawlId)) { $total_results = DB::getInstance()->selectValue("SELECT count(*) FROM `domains` WHERE`domain_crawler_id`='{$crawlId}'"); } else { $total_results = DB::getInstance()->selectValue("SELECT count(*) FROM `domains` WHERE `domain_available`='Y' AND `domain_category`!='N/A' AND `domain_crawler_id`='0'"); } echo $total_results; if (count($rows) < 1) { stderr('Sorry, <b>no</b> domains to show you yet!'); } $backLinksData = getBackLinksByDomains($rows); $isPremiumUser = (int)$user['paid_fees'] === 1; ?> <div class="panel panel-primary"> <div class="panel-heading">Search for expired domains quickly.</div> <div class="panel-body"> <form action="results.php" method="get" class="form-horizontal container-fluid" role="form"> <div class="row form-group"> <div class="col-sm-6 text-right"> <label for="" class="control-label">Domain Contains:</label> </div> <div class="col-sm-6"> <input type="text" name="keywords" class="form-control" size="40" /> </div> </div> <div class="row form-group"> <div class="col-sm-6 text-right"> <label for="" class="control-label">Anchor Contains:</label> </div> <div class="col-sm-6"> <input type="text" name="anchor" class="form-control" size="40" /> </div> </div> <div class="row form-group"> <div class="col-sm-6 text-right"> <label class="control-label">DA:</label> </div> <div class="col-sm-6"> <input type="number" min="0" max="100" name="da" value="0" class="form-control" /> </div> </div> <div class="row form-group"> <div class="col-sm-6 text-right"> <label class="control-label">PA:</label> </div> <div class="col-sm-6"> <input type="number" min="0" max="100" name="pa" value="0" class="form-control" /> </div> </div> <div class="row form-group"> <div class="col-sm-6 text-right"> <label class="control-label">TF:</label> </div> <div class="col-sm-6"> <input type="number" min="0" max="100" name="tf" value="0" class="form-control" /> </div> </div> <div class="row form-group"> <div class="col-sm-6 text-right"> <label class="control-label">CF:</label> </div> <div class="col-sm-6"> <input type="number" min="0" max="100" name="cf" value="0" class="form-control" /> </div> </div> <div class="row form-group"> <div class="col-sm-6 text-right"> <label class="control-label">Domains Born After:</label> </div> <div class="col-sm-6"> <input type="number" min="1990" max="2016" name="age" value="1999" class="form-control" /> </div> </div> <div class="row form-group"> <div class="col-sm-6 text-right"> <label class="control-label" style="display: inline-block;">&nbsp;</label> </div> <div class="col-sm-6 text-right"> <button type="submit" name="submit" class="btn btn-default">Search</button> </div> </div> </form> </div> <div class="panel-footer">Search for domains using <b>your</b> criteria.</div> </div> <div class="panel panel-primary"> <div class="panel-heading">Browse Domains - <b>*<font color="orange">spam</font>*</b> = Potential spam domain! <b>*<font color="red">HP</font>*</b> = A homepage link points to this domain!</div> <div class="panel-body"> <table class="table table-striped table-condensed table-hover table-responsive"> <thead> <tr> <th>Alexa</th> <th>Domain / Category</th> <th><a href="expired-domains.php?sort=domain_moz_da">DA</a></th> <th><a href="expired-domains.php?sort=domain_moz_pa">PA</a></th> <th><a href="expired-domains.php?sort=domain_tf">TF</a></th> <th><a href="expired-domains.php?sort=domain_cf">CF</a></th> <th><a href="expired-domains.php?sort=domain_indexed">Indexed</a></th> <th><a href="expired-domains.php?sort=domain_age">Age</a></th> <th>BL</th> <th><a href="expired-domains.php?sort=domain_ref_domains">RD</a></th> <th>Found</th> <?php if ($canEdit): ?> <th>Actions</th> <?php endif; ?> </tr> </thead> <tbody> <?php foreach ($rows as $row) { ?> <?php //$bgcolor = ($bgcolor == '#eeeeee'? '#ffffff': '#eeeeee'); $domID = $row['domain_id']; $domNM = $row['domain_name']; $domDT = $row['domain_date']; $domAL = $row['domain_alexa_rank']; $domDA = $row['domain_moz_da']; $domPA = $row['domain_moz_pa']; $domTF = $row['domain_tf']; $domCF = $row['domain_cf']; $domRD = $row['domain_ref_domains']; $domDC = $row['domain_age']; $domIN = $row['domain_indexed']; $domHP = $row['domain_homepage']; $domCT = $row['domain_category']; $time_1 = date('Y-m-d H:i:s', strtotime($domDT . ' +1 hour')); $time_2 = date('Y-m-d H:i:s', time()); $string = $domNM; $array = array("sunglasses","payday","casino","viagra","cashloans","loans","sex","porn","xxx"); $spam = 0; foreach ($array as $token) { if (stristr($string, $token) !== FALSE) { $spam = 1; } } ?> <tr> <td><?php echo htmlspecialchars($domAL); ?></td> <td> <?php $domainUrl = $isPremiumUser ? $domNM : getObscuredUrl($domNM); $domainCat = ($domCT == "N/A") ? "<font color=\"red\"><b>Uncategorized</b></font>" : "<font color=\"green\"><b>{$domCT}</b></font>"; ?> <a href="domain-details.php?id=<?php echo $domID; ?>"><b><?php echo htmlspecialchars($domainUrl); ?></b></a> <b>in</b> <?php echo $domainCat; ?> <?php if ($time_2 <= $time_1) { ?> <b>(<font color="red">NEW</font>)</b> <?php } ?> <?php if ($spam) { ?> <b>*<font color="orange">spam</font>*</b> <?php } ?> <?php if ($domHP) { ?> <b>*<font color="red">HP</font>*</b> <?php } ?> </td> <td> <?php echo $domDA; ?> </td> <td> <?php echo $domPA; ?> </td> <td> <?php echo $domTF; ?> </td> <td> <?php echo $domCF; ?> </td> <td> G=<?php if ($domIN == 0) { echo "<font color=\"red\"><b>No</b></font>"; } else { echo "<font color=\"green\"><b>Yes</b></font>"; } ?> </td> <td> <?php if ($domDC == "????") { echo "<b><font color=\"red\">????</font></b>"; } else { echo $domDC; } ?> </td> <td> <?= isset($backLinksData[$domNM]) ? $backLinksData[$domNM] : 0; ?> </td> <td> <?php if (empty($domRD)) { echo "-"; } else { echo $domRD; } ?> </td> <td> <b><?php echo date("m.d.y", strtotime($domDT)); ?></b> </td> <?php if ($canEdit): ?> <td>(<a href="master-edit-domain.php?id=<?php echo $domID ?>">e</a>)-(<a href="master-delete-domain.php?id=<?php echo $domID ?>" onclick="return confirm('Are you sure you want to delete this domain?');">d</a>)</td> <?php endif; ?> </tr> <?php } ?> </tbody> </table> </div> <div class="panel-footer text-center"> <?php pagination($page, $total_results, $max_results) ?> </div> </div> <?php include('includes/footer.php'); 上的1779033703 << 30(32位有符号整数),您正在遇到溢出,因此它再次从int开始。 int.MinValue可以处理更大的值,因此不会受到溢出的影响。

尝试使用BigInteger(64位有符号整数),您将看到与long相同的结果。