Icy North Technologies Forum Index Icy North Technologies
User Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

string format %x of negative number

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Icy North Technologies Forum Index -> Language
View previous topic :: View next topic  
Author Message
nanotiger



Joined: 12 Dec 2009
Posts: 2

PostPosted: Sat Dec 12, 2009 11:53 am    Post subject: string format %x of negative number Reply with quote

Hi,

This is a simple question that puzzles me. Why string.format("%u %x %X") outputs 0 for all negative numbers.

Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> = string.format("%d, %i, %u, %x, %X", -100,-100, -100, -100, -100)
-100, -100, 0, 0, 0
Back to top
View user's profile Send private message
lhf



Joined: 20 Feb 2006
Posts: 175
Location: Rio de Janeiro, Brazil

PostPosted: Sat Dec 12, 2009 7:27 pm    Post subject: Reply with quote

Under Linux and Mac OS X, I get

-100, -100, 4294967196, ffffff9c, FFFFFF9C

Anyway, %u, %x, %X only handles unsigned numbers.
Back to top
View user's profile Send private message Visit poster's website
nanotiger



Joined: 12 Dec 2009
Posts: 2

PostPosted: Sat Dec 12, 2009 8:13 pm    Post subject: Reply with quote

Weird, I've tested it on Mac OSX and an embedded system with ARM processor. Both report
> = string.format("%d, %i, %u, %x, %X", -100,-100, -100, -100, -100)
-100, -100, 0, 0, 0

I would expect Lua handles %u, %x, %X as in C just like your result.
int main()
{
printf("%d, %i, %u, %x, %X\n", -100, -100, -100, -100, -199);
}
-100, -100, 4294967196, ffffff9c, FFFFFF9C

Are there different options to build Lua which might cause the difference?
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Icy North Technologies Forum Index -> Language All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group